[英]Parse json using javascript with multiple object set
我的服務器輸出如下。我想從JSON輸入中獲取“結果” 。
我的JSON輸入是
{
"header":{
"type":"esummary",
"version":"0.3"
},
"result":{
"28885854":{
"uid":"28885854",
"pubdate":"2017 Sep 8",
"epubdate":"2017 Sep 8",
"source":"J Org Chem",
}
}
}
而且我只喜歡javascript。任何人都可以幫助我做到這一點。
編輯 :
我嘗試了從服務器獲取JSON的代碼
var json = JSON.stringify(temp1);
console.log(json)
我在控制台中的原始輸出是這樣的。
“ {” header“:{” type“:” esummary“,” version“:” 0.3“},” result“:{” 28885854“:{” uid“:” 28885854“,” pubdate“:” 2017 Sep 8 “,” epubdate“:” 2017 Sep 8“,” source“:” J Org Chem“,” authors“:[{” name“:” Farmer LA“,” authtype“:” Author“,” clusterid“:” “},{” name“:” Haidasz EA“,” authtype“:” Author“,” clusterid“:”“},{” name“:” Griesser M“,” authtype“:” Author“,” clusterid“ :“”},{“ name”:“ Pratt DA”,“ authtype”:“ Author”,“ clusterid”:“”}],“ lastauthor”:“ Pratt DA”,“ title”:“ Phenoxazine:A Privileged自由基捕獲抗氧化劑的支架。“,” sorttitle“:”吩惡嗪是自由基捕獲抗氧化劑的一種特權支架“,” volume“:”“,” issue“:”“,” pages“:”“,” lang“:[ “ eng”],“ nlmuniqueid”:“ 2985193R”,“ issn”:“ 0022-3263”,“ essn”:“ 1520-6904”,“ pubtype”:[“ Journal Article”],“ recordstatus”:“ PubMed -由發布商提供,“,” pubstatus“:” 10“,” articleids“:[{” idtype“:” pubmed“,” idtypen“:1,” value“:” 28885854“},{” idtype“:” doi“,” idtypen“:3,” value“:” 10.1021 / acs.joc.7b02025“},{” idtype“:” rid“,” idtypen“:8,” value“:” 28885854“},{” idtype“:” eid“,” idtypen“:8,” value“ :“” 28885854“}],”歷史“:[{” pubstatus“:” entrez“,” date“:” 2017/09/09 06:00“},{” pubstatus“:” pubmed“,” date“: “ 2017/09/09 06:00”},{“ pubstatus”:“ medline”,“ date”:“ 2017/09/09 06:00”}],“引用”:[],“屬性”:[ “具有摘要”],“ pmcrefcount”:“”,“完整期刊名稱”:“有機化學雜志”,“ elocationid”:“ doi:10.1021 / acs.joc.7b02025”,“ doctype”:“引用”,“ srccontriblist“:[],” booktitle“:”“,” medium“:”“,” edition“:”“,” publisherlocation“:”“,” publishername“:”“,” srcdate“:”“,”報告編號“:”“,” availablefromurl“:”“,” locationlabel“:”“,” doccontriblist“:[],” docdate“:”“,” bookname“:”“,” chapter“:”“,” sortpubdate“ :“” 2017/09/08 00:00“,” sortfirstauthor“:” Farmer LA“,” vernaculartitle“:”“},” uids“:[” 28885854“]}} ”
我認為您正在尋找的只是.result
。 如果到目前為止您只有JSON字符串,也許您還需要JSON.parse(...)
。
var obj = { "header": { "type": "esummary", "version": "0.3" }, "result": { "28885854": { "uid": "28885854", "pubdate": "2017 Sep 8", "epubdate": "2017 Sep 8", "source": "J Org Chem", } } }; console.log(obj.result); // To address edits above and comments below: console.log(obj.result["28885854"].source);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.