2012-10-24 59 views
-1

我有下面的代码来检索json响应。我需要提取属性'申请人'并将其放到html文本字段。但是我不知道该怎么做。我可以在控制台中看到响应,但文本字段显示[对象对象],如何将其检索到文本字段?任何提示?谢谢。从json响应解析属性

<html> 
<head> 
<script type="text/javascript" 

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript"> 


document.getElementById('sudata').value = budata; 

} 
}); 
</script> 
</head> 
<body> 
<form name="form1" id="form1"> 
<input type="text" name="sudata" id="sudata" value="" size="100"> 
</form> 
</body> 
</html> 

的响应是在这里:

{"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"} 
     }, 
       { 
      "@sequence": "5", 
      "text": {"$": "C07C 57/ 38   A I"} 
     }, 
       { 
      "@sequence": "6", 
      "text": {"$": "C07C 229/ 42   A I"} 
     } 
     ]}, 
     "patent-classifications": {"patent-classification":  [ 
       { 
      "@sequence": "1", 
      "classification-scheme":   { 
      "@office": "EP", 
      "@scheme": "EC" 
      }, 
      "classification-symbol": {"$": "A61K9/00M5"} 
     }, 
       { 
      "@sequence": "2", 
      "classification-scheme":   { 
      "@office": "EP", 
      "@scheme": "EC" 
      }, 
      "classification-symbol": {"$": "A61K31/19"} 
     }, 
       { 
      "@sequence": "3", 
      "classification-scheme":   { 
      "@office": "EP", 
      "@scheme": "EC" 
      }, 
      "classification-symbol": {"$": "A61K31/216"} 
     } 
     ]}, 
     "application-reference":  { 
     "@doc-id": "16272416", 
     "document-id":   [ 
        { 
      "@document-id-type": "docdb", 
      "country": {"$": "EP"}, 
      "doc-number": {"$": "05808069"}, 
      "kind": {"$": "A"} 
      }, 
        { 
      "@document-id-type": "epodoc", 
      "doc-number": {"$": "EP20050808069"}, 
      "date": {"$": "20051019"} 
      }, 
        { 
      "@document-id-type": "original", 
      "doc-number": {"$": "05808069"} 
      } 
     ] 
     }, 
     "priority-claims": {"priority-claim":  [ 
       { 
      "@sequence": "1", 
      "@kind": "national", 
      "document-id":   [ 
         { 
       "@document-id-type": "epodoc", 
       "doc-number": {"$": "WO2005IN00339"}, 
       "date": {"$": "20051019"} 
      }, 
         { 
       "@document-id-type": "original", 
       "doc-number": {"$": "IN2005000339"} 
      } 
      ] 
     }, 
       { 
      "@sequence": "2", 
      "@kind": "national", 
      "document-id":   [ 
         { 
       "@document-id-type": "epodoc", 
       "doc-number": {"$": "IN2004DE02332"}, 
       "date": {"$": "20041122"} 
      }, 
         { 
       "@document-id-type": "original", 
       "doc-number": {"$": "DE23322004"} 
      } 
      ] 
     } 
     ]}, 
     "parties":  { 
     "applicants": {"applicant":   [ 
        { 
      "@sequence": "1", 
      "@data-format": "epodoc", 
      "applicant-name": {"name": {"$": "VENUS REMEDIES LTD [IN]"}} 
      }, 
        { 
      "@sequence": "1", 
      "@data-format": "original", 
      "applicant-name": {"name": {"$": "VENUS REMEDIES LIMITED"}} 
+0

任何帮助?请。 – user1767121

回答

0

budata你变量包含的阵列。你的元素的value属性是一个字符串属性,所以当你为它分配一个对象时,该对象首先被Object :: toString()转换;这将返回[object Object]

如果你想显示申请人财产的完整内容,请尝试:

document.getElementById('sudata').value = JSON.stringify(budata); 

如果你只是想显示阵列的特定部分,你必须指定你的预期的输出字符串是。

+0

var budata = oData; document.getElementById('sudata')。value = JSON.stringify(budata); 感谢您的帮助,我现在可以将整体放入文本字​​段。 但我怎样才能得到'申请人'的部分?或者我该如何寻找阵列中的“申请人”财产? – user1767121

+0

我不确定你在这里问什么。你能否在文本字段中粘贴你看到的确切字符串,并提供你想要的确切字符串? – Waxen

+0

我在文本字段中看到了整个响应(我把它放在我的代码下面),我只想看到VENUS REMEDIES LTD(在响应的底部)部分。 – user1767121