- Java EE 8 and Angular
- Prashant Padmanabhan
- 329字
- 2021-07-02 19:22:32
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.
- Extending Jenkins
- DBA攻堅(jiān)指南:左手Oracle,右手MySQL
- Java入門經(jīng)典(第6版)
- Effective C#:改善C#代碼的50個(gè)有效方法(原書第3版)
- PyTorch自動(dòng)駕駛視覺感知算法實(shí)戰(zhàn)
- 營(yíng)銷數(shù)據(jù)科學(xué):用R和Python進(jìn)行預(yù)測(cè)分析的建模技術(shù)
- TypeScript圖形渲染實(shí)戰(zhàn):基于WebGL的3D架構(gòu)與實(shí)現(xiàn)
- Yocto for Raspberry Pi
- Jenkins Continuous Integration Cookbook(Second Edition)
- Terraform:多云、混合云環(huán)境下實(shí)現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- C++寶典
- 從零開始學(xué)Python網(wǎng)絡(luò)爬蟲
- SciPy Recipes
- 代碼閱讀
- C++從入門到精通(第6版)