- 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.
- C++程序設(shè)計(jì)教程
- ClickHouse性能之巔:從架構(gòu)設(shè)計(jì)解讀性能之謎
- Oracle從新手到高手
- Visual C++實(shí)例精通
- Java Web基礎(chǔ)與實(shí)例教程
- Creating Stunning Dashboards with QlikView
- 詳解MATLAB圖形繪制技術(shù)
- 寫給程序員的Python教程
- SQL Server 2008 R2數(shù)據(jù)庫技術(shù)及應(yīng)用(第3版)
- Python函數(shù)式編程(第2版)
- Appcelerator Titanium:Patterns and Best Practices
- Maven for Eclipse
- 例說FPGA:可直接用于工程項(xiàng)目的第一手經(jīng)驗(yàn)
- Building Microservices with .NET Core 2.0(Second Edition)
- Scratch超人漫游記:創(chuàng)意程序設(shè)計(jì):STEAM創(chuàng)新教育指南