`
Rainbow702
  • 浏览: 1065160 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类

JSON的格式

阅读更多

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics