如何解析包含“。”的json以其键名

时间:2018-08-02 14:29:32

标签: jsonparser

{
    "key" : "value",
    "array.fruits" : [
        { "key" : 1 },
        { "key" : 2, "dictionary": {
                "a": "Apple",
                "b": "Butterfly",
                "c": "Cat",
                "d": "Dog"
            } },
        { "key" : 3 }
    ]
}

如何在json查询中解析键“ array.fruits”。

1 个答案:

答案 0 :(得分:1)

您可以使用bracket notation property accessor来获得所需的值:

const data = {
    "key" : "value",
    "array.fruits" : [
        { "key" : 1 },
        { "key" : 2, "dictionary": {
                "a": "Apple",
                "b": "Butterfly",
                "c": "Cat",
                "d": "Dog"
            } },
        { "key" : 3 }
    ]
}

console.dir(data["array.fruits"])