jquery 解析json

1.

 var str='{ "name": "John" }';
    var obj = eval('(' + str + ')'); 
    alert( obj.name);

    var str2="{ 'name': 'John' }";
    var obj2 = eval('(' + str2 + ')'); 
    alert( obj2.name);

    var str3="{ name: 'John' }";
    var obj3 = eval('(' + str3 + ')'); 
    alert( obj3.name);

2.

  var str='{ "name": "John" }';
    var obj = jQuery.parseJSON(str)
    alert("1"+ obj.name);

3.

 var str = '{ "name": "mady", "age": "24" }';
        var obj = JSON.parse(str);
        alert(obj.name);
posted @ 2015-08-03 12:18  刘阳|lyang|yangakw  阅读(104)  评论(0编辑  收藏  举报