使用 JSON 数组与 JSON 对象有什么区别? [英] What are the differences between using JSON arrays vs JSON objects?
本文介绍了使用 JSON 数组与 JSON 对象有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用JSON数组有什么区别和优势:
What are the difference and advantages of using JSON arrays:
{
thing:[
{ },
{ }
]
}
与 JSON 对象对比:
versus JSON objects:
{
thing:{
{ },
{ }
}
}
推荐答案
array
和 object
的区别在于
使用 key
和 value
设置对象,例如:
Objects are set up using a key
and value
like:
person.age = 15;
如果 key
值是一个变量,那么可以像这样访问它:
If the key
value is a variable, then one could access it like:
var key = "age";
alert(person[key]);
数组使用整数[1]索引并取值.
Arrays use an integer[1] index and take a value.
player[1].score += 1000;
[1] 是的,我知道,在 JavaScript 中,整数索引实际上在幕后变成了字符串.忽略那个.当您想到 JSON 时,请考虑使用整数值的数组.
[1] Yes, I know, in JavaScript the integer index is really turned into a string behind the scenes. Ignore that. Think of arrays taking an integer value ESPECIALLY when you think of JSON.
这篇关于使用 JSON 数组与 JSON 对象有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文