如何使用jquery打印json值

时间:2015-09-09 11:34:10

标签: jquery json

[  
   Object   {  
      id: "1",
      name: "sakthivel"
   },
   Object   {  
      id: "2",
      name: "sathish"
   },
   Object   {  
      id: "3",
      name: "saravanan"
   },
   Object   {  
      id: "4",
      name: "murugan"
   },
   Object   {  
      id: "5",
      name: "velmurugan"
   },
   Object   {  
      id: "6",
      name: "vadivelan"
   }
]

1 个答案:

答案 0 :(得分:1)

尝试JSON.parse(),如下所述:

var json = '{"value":"validJSON"}';
var obj = JSON.parse(json);
console.log(json);

完整摘录:

var json = (function() {
    var json = null;
    $.ajax({
        'async': false,
        'global': false,
        'url': "localhost/download/index.php/home/getarray";,
        'dataType': "json",
        'success': function(data) {
            var parsed_result = JSON.parse(data);  //parsing here
            return parsed_result; //return when data is parsed successfully
        }
    });
})();
console.log(json);