jquery json解析两个代码一个不工作另一个不工作
我有以下代码用于解析来自服务器的jason响应。我还包括各自的答复。第一个代码有效,但第二个代码无效。你能给我一个提示吗?谢谢 第一个代码:jquery json解析两个代码一个不工作另一个不工作,jquery,ajax,json,rest,jsonp,Jquery,Ajax,Json,Rest,Jsonp,我有以下代码用于解析来自服务器的jason响应。我还包括各自的答复。第一个代码有效,但第二个代码无效。你能给我一个提示吗?谢谢 第一个代码: <html> <head> <script type="text/javascript" 您不想迭代书目数据的内容,只想从中获取一个属性 替换这个 $.each(oData['ops:world-patent-data']['exchange-documents']['bibliographic-data'],
<html>
<head>
<script type="text/javascript"
您不想迭代书目数据的内容,只想从中获取一个属性
替换这个
$.each(oData['ops:world-patent-data']['exchange-documents']['bibliographic-data'],
function(iIndex, mValue) {
console.log(mValue['publication-reference'])
}
);
因此:
console.log(oData['ops:world-patent-data']['exchange-documents']['bibliographic-data']['publication-reference']);
获取文档编号:
console.log(oData['ops:world-patent-data']['exchange-documents']['bibliographic-data']['publication-reference']['document-id'][0]['doc-number']);
如果我正确阅读此内容,则结构中缺少一个元素:
ops:world-patent-data.exchange-documents.exchange-document.bibliographic-data.publication-reference
因此,在['exchange-document']
把它放在一个提琴文档中,看看这是否有助于您:
非常感谢。现在我在控制台中收到未定义的消息。谢谢。你的建议行得通。虽然如果我替换为:console.log(oData['ops:world patent data']['exchange-documents']['exchange-document']['书目-data']['publication-reference']['doc-number]);我收到未定义的消息,如何访问文档编号属性??。
var iam = {
"ops:world-patent-data": {
"@xmlns": {
"ops": "http://ops.epo.org",
"$": "http://www.epo.org/exchange",
"ccd": "http://www.epo.org/ccd",
"xlink": "http://www.w3.org/1999/xlink"
},
"ops:meta": {
"@name": "elapsed-time",
"@value": "31"
},
"exchange-documents": {
"exchange-document": {
"@system": "ops.epo.org",
"@family-id": "35636806",
"@country": "EP",
"@doc-number": "1814517",
"@kind": "A1",
"bibliographic-data": {
"publication-reference": {
"document-id": [
{
"@document-id-type": "docdb",
"country": {
"$": "EP"
},
"doc-number": {
"$": "1814517"
},
"kind": {
"$": "A1"
},
"date": {
"$": "20070808"
}},
{
"@document-id-type": "epodoc",
"doc-number": {
"$": "EP1814517"
},
"date": {
"$": "20070808"
}}
]
},
"classifications-ipcr": {
"classification-ipcr": [
{
"@sequence": "1",
"text": {
"$": "A61K 9/ 08 A I"
}},
{
"@sequence": "2",
"text": {
"$": "A61K 31/ 19 A I"
}},
{
"@sequence": "3",
"text": {
"$": "A61K 31/ 216 A I"
}},
{
"@sequence": "4",
"text": {
"$": "A61K 47/ 00 A I"
}}]
}
}
}
}
}
};
$('#me').text(iam["ops:world-patent-data"]["exchange-documents"]["exchange-document"]["bibliographic-data"]["publication-reference"]["document-id"][0]["doc-number"].$);