我有以下代码用于解析来自服务器的 jason 响应。我还包括各自的回应。第一个代码有效,但第二个代码无效。能给个提示吗?谢谢。第一个代码:
<html>
<head>
<script type="text/javascript"
您不想迭代内容,bibliographic-data
而只想从中获取一个属性
替换这个
$.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']
把它放在一个小提琴文件中,看看这是否对你有帮助:http: //jsfiddle.net/pfJjG/1/
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"].$);