happyPawpaw
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>

 

分类:

技术点:

相关文章:

  • 2022-01-02
  • 2021-08-02
  • 2022-02-07
  • 2021-10-11
  • 2022-01-02
  • 2021-10-16
  • 2021-12-31
  • 2021-11-30
猜你喜欢
  • 2021-11-30
  • 2021-11-21
  • 2021-11-18
  • 2021-11-21
  • 2021-06-04
  • 2022-01-02
  • 2021-09-25
相关资源
相似解决方案