您的位置:首页 > Web前端 > JavaScript

JSON的格式

2016-01-14 15:32 621 查看
There are just a few rules that you need to remember:

•Objects are encapsulated within opening and closing brackets { }

•An empty object can be represented by { }

•Arrays are encapsulated within opening and closing square brackets [ ]

•An empty array can be represented by [ ]

•A member is represented by a key-value pair

•The key of a member should be contained in double quotes. (JavaScript does not require this. JavaScript and some parsers will tolerate single-quotes)

•Each member should have a unique key within an object structure

•The value of a member must be contained in double quotes if it's a string (JavaScript and some parsers will tolerates single-quotes)

•Boolean values are represented using the true or false literals in lower case

•Number values are represented using double-precision floating-point format. Scientific notation is supported

•Numbers should not have leading zeroes

•"Offensive"" characters in a string need to be escaped using the backslash character

•Null values are represented by the null literal in lower case

•Other object types, such as dates, are not properly supported and should be converted to strings. It becomes the responsability of the parser/client to manage this.

•Each member of an object or each array value must be followed by a comma if it's not the last one

•The common extension for json files is '.json'

•The mime type for json files is 'application/json'

例子:

{
"anObject": {
"numericProperty": -122,
"stringProperty": "An offensive \" is problematic",
"nullProperty": null,
"booleanProperty": true,
"dateProperty": "2011-09-23"
},
"arrayOfObjects": [
{
"item": 1
},
{
"item": 2
},
{
"item": 3
}
],
"arrayOfIntegers": [
1,
2,
3,
4,
5
]
}


在线JSON转换及格式化网址: http://www.freeformatter.com/json-formatter.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: