我有以下代碼解析來自服務器的傑森響應。我也包括各自的迴應。第一個代碼有效,但第二個代碼沒有。你能給一個提示嗎?謝謝。 首先代碼:jquery json解析兩個代碼一個工作其他不是
<html>
<head>
<script type="text/javascript"
我有以下代碼解析來自服務器的傑森響應。我也包括各自的迴應。第一個代碼有效,但第二個代碼沒有。你能給一個提示嗎?謝謝。 首先代碼:jquery json解析兩個代碼一個工作其他不是
<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"].$);
謝謝。現在我在控制檯中收到未定義的消息。 – user1767121
謝謝。您的建議有效。如果我替換爲:console.log(oData ['ops:world-patent-data'] ['exchange-documents'] ['exchange-document'] ['bibliographic-data'] ['publication-reference'] [ 'DOC-號碼)']);我收到未定義的消息,我怎麼能達到doc-number屬性? – user1767121
我在答案中更新了它。 – lrsjng