zoukankan      html  css  js  c++  java
  • json对象转换成string的方法

    jquery打印某个json对象的方法:
    <script>
    var jsonToString=typeof JSON !="undefined"? JSON.stringify :function(obj){
      var arr =[];
      $.each(obj,function(key, val){
        var next = key +": ";
        next += $.isPlainObject(val)? jsonToString(val): val;
        arr.push( next );
      });
      return"{ "+  arr.join(", ")+" }";
    };
    var jsonstring = {
                    "modeldata" : [ {
                        "chart.data" : 12,
                        "chart.colors" : "red",
                        "chart.labels" : "John(12%)",
                        "chart.exploded" : 10
                    }, {
                        "chart.data" : 18,
                        "chart.colors" : "blue",
                        "chart.labels" : "Richard(18%)",
                        "chart.exploded" : 20
                    }, {
                        "chart.data" : 25,
                        "chart.colors" : "green",
                        "chart.labels" : "James(25%)",
                        "chart.exploded" : 20
                    }, {
                        "chart.data" : 45,
                        "chart.colors" : "pink",
                        "chart.labels" : "Green(45%)",
                        "chart.exploded" : 20
                    } ],
                    "operate" : [ "hello" ]
                };
                alert(JSON.jsonToString(jsonstring));
     
    </script>
  • 相关阅读:
    网络流 方阵移动
    NOI2019滚粗记
    PKUSC2019游记
    CQOI十二省联考游记
    数学结论题 书堆
    计算几何 大灾变
    51NOD 1773 A国的贸易
    BZOJ 3944
    51Nod 1238
    NOIP2018游记
  • 原文地址:https://www.cnblogs.com/happyPawpaw/p/2468042.html
Copyright © 2011-2022 走看看