鑑於我從掌上API的響應收到以下test.json
,如何提升嵌套兩層深度的JSON對象的值?
{
"complete": 1,
"error": null,
"list": {
"1000055792": {
"excerpt": "Some Text",
"favorite": "0",
"given_title": "Some Title",
"given_url": "Some URL",
"has_image": "0",
"has_video": "0",
"is_article": "1",
"is_index": "0",
"item_id": "1000055792",
"resolved_id": "1000055792",
"resolved_title": "Title",
"resolved_url": "Some URL",
"sort_id": 700,
"status": "1",
"time_added": "1438646514",
"time_favorited": "0",
"time_read": "1439025088",
"time_updated": "1439025090",
"word_count": "10549"
},
"1000102810": {
"excerpt": "Some Text",
"favorite": "0",
"given_title": "Title",
"given_url": "Some URL",
"has_image": "1",
"has_video": "0",
"is_article": "1",
"is_index": "0",
"item_id": "1000102810",
"resolved_id": "1000102810",
"resolved_title": "Title",
"resolved_url": "Resolved URL",
"sort_id": 650,
"status": "1",
"time_added": "1440303789",
"time_favorited": "0",
"time_read": "1440320729",
"time_updated": "1440320731",
"word_count": "3219"
}
如何訪問鍵的值一樣resolved_title
和word_count
。它們嵌套在一個數字的對象內,與id
相同,它本身嵌套在list
的內部。我搜索並找到了一種使用jq訪問嵌套對象的方法。但是,如何訪問嵌入在主list
對象內的另一個對象內的值?
此外,ID是不同的,不順序,所以我不認爲遞歸是可能的,但我可能是錯的。我打算對這些數據進行的操作是僅提取每個項目的resolved_title
和word_count
值,並將它們保存爲兩列電子表格。
在此先感謝!
什麼語言你在做這個嗎? JavaScript的?你添加了「命令行」標籤,那麼你是否使用node.js?或其他一些語言? –
@KenB問題和標籤都提及[標籤:jq] – tripleee
啊對不起,我以爲'jq'意味着jQuery,現在我看到它是一個命令行工具用於瀏覽JSON –