我可以依靠JSON数组的顺序吗?

Ben*_*ett 3 javascript json

显然,我不能依赖JSON中键/值对的排序。例如,JSON解析器可以解释

{
    "someKey" : "someValue",
    "anotherKey" : "anotherValue",
    "evenAnotherKey" : "evenAnotherValue"
}
Run Code Online (Sandbox Code Playgroud)

{
    "anotherKey" : "anotherValue",
    "someKey" : "someValue",
    "evenAnotherKey" : "evenAnotherValue"
}
Run Code Online (Sandbox Code Playgroud)

合法,但是我可以依靠JSON 数组的顺序吗?例如,JSON解析器可以解释

{
    "arrayKey" : ["firstElement", "secondElement", "thirdElement"]
}
Run Code Online (Sandbox Code Playgroud)

{
    "arrayKey" : ["secondElement", "firstElement1", "thirdElement"]
}
Run Code Online (Sandbox Code Playgroud)

合法吗 我以为没有,但是我的朋友告诉我我不正确。

phi*_*ipp 6

是的你可以!数组已制成,因此顺序很重要!那就是将对象与数组分开的原因。特别是在JS和JSON中。