• json To STR


        <script type="text/javascript">
    function JsonToStr(o) {
    var r = [];
    if (typeof o == "string" || o == null) {
    return o;
    }
    if (typeof o == "object") {
    if (!o.sort) {
    r[0] = "{"
    for (var i in o) {
    r[r.length] = i;
    r[r.length] = ":";
    r[r.length] = JsonToStr(o[i]);
    r[r.length] = ",";
    }
    r[r.length - 1] = "}"
    } else {
    r[0] = "["
    for (var i = 0; i < o.length; i++) {
    r[r.length] = JsonToStr(o[i]);
    r[r.length] = ",";
    }
    r[r.length - 1] = "]"
    }
    return r.join("");
    }
    return o.toString();
    }


    window.onload = function () {
    var str = '{ "people": [{ "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb"},{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }]} ';
    alert(JsonToStr( eval('('+str+')')));

    // alert(eval(str));
    //alert(JsonToStr(str));
    }


    </script>


     

  • 相关阅读:
    增加文章
    网站之注册
    C#常用的引用
    Session.Abandon和Session.Clear有何不同 (转)
    C#文件路径的写法
    UpdatePanel的用法详解
    [转]asp:ScriptManager
    Git 常用命令
    AJAX请求 $.post方法的使用
    a 标签中调用js的几种方法
  • 原文地址:https://www.cnblogs.com/rhythmK/p/2406564.html
Copyright © 2020-2023  润新知