【发布时间】:2017-08-05 15:12:47
【问题描述】:
我用jq解析一个json文件:
jq .response[1].text file.json
它工作正常,但每次我必须输入数字 .response[2].text、.response[3].text 等。我想一次获取所有值(200 个值)
但是当我这样做时:
jq .response[].text file.json
它给出一个错误:不能用字符串“text”索引数字
文件如下所示:
{
"response": [
1000,
{
"id": ,
"date": ,
"owner_id": ,
"from_id": ,
"post_type": "post",
"text": "blabla",
"attachment": {
"type": "photo",
"photo": {
"pid": ,
"aid": -7,
"owner_id":
}
},
"attachments": [
{
"type": "photo",
"photo": {
}
},
{
"type": "link",
"link": {
"url": "",
"title": "",
"description": "",
"target": "external"
}
}
],
"post_source": {
"type": "vk"
},
"comments": {
"count": 0,
"groups_can_post": true,
"can_post": 1
},
},
{
"id": ,
"date": ,
"owner_id": ,
"from_id": ,
"post_type": "post",
"text": "blabla",
"attachment": {
"type": "link",
"link": {
"url": "",
"title": "",
"description": "",
"target": "external",
"
}
【问题讨论】:
-
你能提供一个简短的例子来说明
file.json的样子吗?另外,你有什么版本的jq?我无法用jq1.5 重现错误,我认为这是file.json的一个例子。 -
我添加了上面的例子。我的 jq 版本是 1.5。
-
response[0]不是对象;这是一个数字。