【问题标题】:How can I parse JSON data?如何解析 JSON 数据?
【发布时间】:2013-07-31 07:02:08
【问题描述】:

我如何解析下面的 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"]}]}})

【问题讨论】:

标签: jquery json jsonp


【解决方案1】:

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.

【讨论】:

  • @lolwut,因为我是 JSON 解析的新手。你能根据我的数据给我看一些例子吗?这对我有很大的帮助..
  • @lolwut,感谢您提供的信息。但是我在数据字段中获取了这个 JSON 数据,所以我怎样才能在 $.parseJSON 中写下这个数据字段。它应该是这样的 $. parseJSON('数据');还是其他方式??
  • 没有。只需使用$.parseJSON(data);
  • @lolwut,然后我得到 jsonObj 为空 [Break On This Error] alert(jsonObj.response.docs[0].c_application_number);
  • @lolwut,我正在使用此代码,并且数据包含 JSON 类型的实际响应。 var jsonObj = $.parseJSON(data); alert(jsonObj.response.docs[0].c_application_number);
猜你喜欢
  • 1970-01-01
  • 2020-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-03
  • 2014-05-23
相关资源
最近更新 更多