官术网_书友最值得收藏!

Working with JSON documents

To get an understanding of how this works, consider the following JSON document saved in a file called demo.json (it can be any file), which contains an array of JSON objects with the name and priority key-value pairs:

[
{
"name": "Feature: Add support for X",
"priority": 1
},
{
"name": "Bug: Fix search performance",
"priority": 2
},
{
"name": "Feature: Create mobile page",
"priority": 3
}
]

Now, before looking at the API, it is important to understand how we need to perceive this JSON document. JSON defines only two data structures, one being an array that contains a list of values and the other an object that is just a name key-value pair. There are six value types in JSON, namely:

  • String
  • Number
  • Object
  • Array
  • Boolean
  • Null

In the previous document, the square brackets around the content denote an array that has multiple objects as its values. Let's take a look at the first JSON object, as follows:

{
"name": "Feature: Add support for X",
"priority": 1
}

The curly braces, {}, denote a JSON object that contains a key-value pair. The key must be a string in quotes followed by the value, which must be a valid JSON data type. In the previous case, we have the string in quotes, "Feature: Add support for X", and this maps to a String data type. The value of the "priority" key is a number data type, given as 1. Since the value can be any JSON data type, you could also have nested objects and arrays as values of the JSON object. Here's an example of that, showing the "ticket" key having an array as its value, which contains objects:

{ 
"name": "Feature: Add support for X",
"priority": 1,
"ticket": [
{
"name": "Feature: add new ticket",
"priority": 2
},
{
"name": "Feature: update a ticket",
"priority": 2
}
]
}

Having built an understanding of this document structure, let's look at the API.

主站蜘蛛池模板: 长治县| 琼结县| 霍城县| 方山县| 甘南县| 丹东市| 昌都县| 綦江县| 四川省| 夏津县| 科尔| 墨竹工卡县| 铜梁县| 鸡东县| 海丰县| 连云港市| 海淀区| 红安县| 龙胜| 安陆市| 鄯善县| 沾化县| 大荔县| 成安县| 衢州市| 栾川县| 寿阳县| 泰和县| 宜春市| 明溪县| 阳信县| 涡阳县| 西和县| 佛冈县| 喀喇| 石阡县| 雷波县| 高州市| 弥勒县| 吉林市| 克山县|