Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

javascript - 是否保留JSON列表中元素的顺序?(Is the order of elements in a JSON list preserved?)

I've noticed the order of elements in a JSON object not being the original order.(我注意到JSON对象中元素的顺序不是原始顺序。)

What about the elements of JSON lists?(JSON列表的元素呢?) Is their order maintained?(他们的订单得到维护吗?)   ask by user437899 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, the order of elements in JSON arrays is preserved.(是的,JSON数组中元素的顺序得以保留。)

From RFC 7159 -The JavaScript Object Notation (JSON) Data Interchange Format (emphasis mine):(从RFC 7159开始-JavaScript对象表示法(JSON)数据交换格式 (重点是我):) 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.(对象是零个或多个名称/值对的无序集合,其中名称是字符串,值是字符串,数字,布尔值,null,对象或数组。) An array is an ordered sequence of zero or more values.(数组是零个或多个值的有序序列。) The terms "object" and "array" come from the conventions of JavaScript.(术语“对象”和“数组”来自JavaScript的约定。) Some implementations do also preserve the order of JSON objects as well, but this is not guaranteed.(一些实现也确实会保留JSON对象的顺序,但这不能保证。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...