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);