我使用jq解析一个JSON文件:
jq .response[1].text file.json
它能正常工作,但每次我都需要输入.number[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
?我无法在jq
1.5 和我认为是file.json
示例的情况下重现错误。 - chepnerresponse[0]
不是一个对象,而是一个数字。 - chepner