【发布时间】:2017-01-14 06:26:15
【问题描述】:
鉴于我从 Pocket API 收到的以下 test.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
-
啊抱歉,我以为
jq指的是jQuery,现在我看到它是一个用于导航JSON 的命令行工具 -
@tripleee 是的,我之前提到过您的线程,但您遇到的问题是嵌套对象的深度一级。我试过了,但很遗憾,它没有用。
标签: json command-line jq pocket