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'
例子:
在线JSON转换及格式化网址: http://www.freeformatter.com/json-formatter.html
•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
相关文章推荐
- 实现跨域请求jsonp方式
- JS 关于(function( window, undefined ) {})(window)写法的理解
- js实例代码
- Requesting JavaScript AST from selection
- js从身份证号中获取出生日期和性别
- js实现prototype扩展的方法(字符串,日期,数组扩展)
- javascript 基础API
- ExtJS5.0 菜鸟的第一天
- ajax传递json字符串写法
- Javascript中, event 的 target 与 currentTarget 的区别
- 在JSP页面中显示动态时间
- Javascript中, setTimeout() 和 setInterval() 的方法
- JSP页面实现自动跳转
- Backbone.js 的最佳应用场景有哪些?
- JavaScript 中 的等号(==)/不等号(!=) 和全等号(===)/非全等号(!==) 的用法
- JavaScript学习笔记
- Javascript闭包
- JavaScript设计模式 --- 方法的链式调用
- js常见问题之为什么点击弹出的i总是最后一个
- IPv6的正则表达式【JAVASCRIPT】