从JSON对返回字符串

时间:2018-03-01 10:31:13

标签: json jsonpath

在JSON对{"字符串":"值"}中,我试图返回字符串。我需要发送什么JSONPath查询?例如,在下面的JSON中,我希望我的查询返回单词" category"数组中的第一行。

谢谢! 托本

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

1 个答案:

答案 0 :(得分:0)

查询是:$ .store.book [:1] .category

[:1] = The item on Position 1
[0:3] = The item on position 1,2,3
[2:4] = The item on position 3,4