是否保留JSON列表中元素的顺序? [英] Is the order of elements in a JSON list preserved?
问题描述
我注意到JSON对象中元素的顺序不是原始顺序.
I've noticed the order of elements in a JSON object not being the original order.
JSON列表的元素呢?他们的订单得到维护吗?
What about the elements of JSON lists? Is their order maintained?
推荐答案
是的,将保留JSON数组中元素的顺序.来自 RFC 7159 -JavaScript对象符号(JSON)数据交换格式 (重点是我的):
Yes, the order of elements in JSON arrays is preserved. From RFC 7159 -The JavaScript Object Notation (JSON) Data Interchange Format (emphasis mine):
对象是零个或多个名称/值的无序集合 对,其中名称是字符串,值是字符串,数字, 布尔值,null,对象或数组.
An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.
一个数组是一个零个或多个值的有序序列.
An array is an ordered sequence of zero or more values.
术语对象"和数组"来自以下约定: JavaScript.
The terms "object" and "array" come from the conventions of JavaScript.
某些实现也确实保留了JSON对象的顺序,但这不能保证.
Some implementations do also preserve the order of JSON objects as well, but this is not guaranteed.
这篇关于是否保留JSON列表中元素的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!