zoukankan      html  css  js  c++  java
  • 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>


     

  • 相关阅读:
    haproxy常用配置
    分区命令(大于2TB的分区)
    css基础-2 div布局
    css基础-1
    2.HTML5基本标签
    1.HTML基本结构、头部、注释
    AWK数组
    nginx rewrite 基础
    nginx location详解
    Linux命令练习.ziw
  • 原文地址:https://www.cnblogs.com/rhythmK/p/2406564.html
Copyright © 2011-2022 走看看