如何解析包含“.”的json在它的键名中

How to parse json that contains "." in its key name

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

如何解析 json 查询中的键 'array.fruits'。

您可以使用 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"])