的JSONObject和JSONArray的区别 [英] Difference between JSONObject and JSONArray
问题描述
有短看看谷歌之后,我发现这个<一href="http://www.dotnetfunda.com/interview/exam4309-difference-json-arrary-vs-json-object.aspx">link描述差,还从一个语法点
After having a short look at Google I found this link that describes the difference, yet from a syntax point of view.
在将之一的编程场景pferred比其他$ P $?
When would one be preferred over the other in a programming scenario?
推荐答案
当您正在使用JSON数据在Android中,你可以使用 JSONArray
来解析JSON其开头阵列支架。在JSON数组用于组织的相关项目的集合(可能是JSON对象)。
例如: [{名:项目1},{名:项目2}]
When you are working with JSON data in Android, you would use JSONArray
to parse JSON which starts with the array brackets. Arrays in JSON are used to organize a collection of related items (Which could be JSON objects).
For example: [{"name":"item 1"},{"name": "item2} ]
在另一方面,你可以使用的JSONObject
时使用JSON开头花括号处理。 JSON对象通常用于包含与一个项键/值对。
例如: {名:ITEM1,说明:一个JSON对象}
On the other hand, you would use JSONObject
when dealing with JSON that begins with curly braces. A JSON object is typically used to contain key/value pairs related to one item.
For example: {"name": "item1", "description":"a JSON object"}
当然,也可以嵌套在另一个JSON数组和对象。这方面的一个常见的例子是一个API,它返回一个包含一些元数据一起匹配您的查询项目的数组的JSON对象:
Of course, JSON arrays and objects may be nested inside one another. One common example of this is an API which returns a JSON object containing some metadata alongside an array of the items matching your query:
{"startIndex": 0, "data": [{"name":"item 1"},{"name": "item2"} ]}
这篇关于的JSONObject和JSONArray的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!