开发者

What is the difference between an JSON and Array?

What is the difference between an JSON and Array? Why do they call JSON Objects and Array Objects.

http://wiki.appcelerator.org/display/guides/Using+TableViews+-+data.js

Is this an Array or JSON? How can i 开发者_StackOverflowidentify?


JSON is a data format that is based on a subset of JavaScript.

A simplified version of the specification is available on the JSON homepage. The full specification is available as an IETF RFC.

Libraries exist in many different languages to convert from a string of JSON data into data structures appropriate for that language (and to go the other way). A list of some of them can be found near the bottom of the JSON homepage.

An array is a data structure common to most programming languages which contains a number of variables in a specific order. JSON has an array data type.

A JSON Object is a serialisation of a collection of key/value pairs. Most programming languages have a matching data structure, such as a hash in Perl or a (simple) object in JavaScript.

In the page you link to, there is no mention of JSON. It has a variable (weatherData) to which is assigned a simple object (using an object literal {}) which has one key (reports) to which is assigned an array (using an array literal []) that contains a number of objects, each of which consists of a bunch of key/value pairs where the values are all strings.

If you were to remove the first line, and the semi-colon at the end, then the example would be a JSON data structure representing the same information. This is because, as I said earlier, JSON is based on a subset of JavaScript and that part of the example conforms to the subset.


It's neither a JSON text (JSON is a text data-interchange format - if it's not a String, it's not JSON) nor an Array.

It's an Object, defined as an object literal, with one property - reports - which is an Array (defined as an array literal) of Object instances with properties describing weather conditions in cities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜