我该如何解析JSON数据?

时间:2011-06-16 21:38:46

标签: jquery json jsonp

我如何在JSON数据下面解析这个数据作为我从服务器返回的数据,我想从这个json数据中提取值和标签,并且必须放在一个弹出窗口中..

例如: - 对于此数据"application_number":"20007524.8"

我想将application_number提取为Application Number并对应于Application Number,其值为20007524.8

任何建议我该怎么做..

jsonp13082({"responseHeader":{"status":0,"Time":3,"params":{"json.wrf":"jsonp13082","wt":"json","q":"8377"}},"response":{"numFound":1,"start":0,"docs":[{"key":"83779616","number":"080","name":"Designated","name":"Non ","number":"27837","date":"2010-08-24T07:00:00Z","name":"Canada","name":"Application","title":"collision detection","date":"2008-03-03T08:00:00Z","id":"414","code":"CA","date":"2009-03-03T08:00:00Z","name":"Michael Henry","mgr_name":"abc","id":"79616","name":"oen","claims":"74","date":"2012-03-03T08:00:00Z","claims":"8","url":"","inventors":["D.","rshi","Pa"],"guid":["23","26","25"],"towners":["XYZ"],"inventors":["D","name2","name3"],"owners":["XYZ"]}]}})

1 个答案:

答案 0 :(得分:7)

jQuery中有一个内置的parseJSON函数。

编辑:使用示例:

// make a reference
var Obj = $.parseJSON('the json object');

alert(Obj.response.docs[0].c_application_number);  

如何?

As you descend into the nodes, the name of the node goes on, so for example if you have a JSON object like this:

{
    "parent": {
        "sibling": "you found a sibling",
        "child": {
            "more_children": "hello"
        }
    }
}

使用这样的代码:

var json = $.parseJSON('{ "parent": { "sibling": "you found a sibling", "child": { "more_children": "hello" } } }');

// I want to get the sibling value
alert(json.parent.sibling);

// I want to get the children value
alert(json.parent.child.more_children);

Demo