当前位置:网站首页>JSON Library Tutorial from scratch (I): starting to learn and organize notes
JSON Library Tutorial from scratch (I): starting to learn and organize notes
2022-06-25 05:17:00 【zhongh58】
Original website : From scratch JSON Library Tutorial - You know
JSON What is it? ?
JSON(JavaScript Object Notation) Is a text format for data exchange .
JSON It's a tree structure , Contains only 6 Type of data :
- null: Expressed as null
- boolean: Expressed as true or false
- number: General representation of floating point numbers , Explain in detail in the next module
- string: Expressed as "..."
- array: Expressed as [ ... ]
- object: Expressed as { ... }
What we want to achieve JSON library , Mainly completed 3 A need :
- hold JSON The text is parsed into a tree data structure (parse).
- Provide an interface to access the data structure (access).
- Convert the data structure into JSON Text (stringify).
JSON There is 6 Type of data , If you put true and false As two types, they are 7 Kind of , We declare an enumeration type for this (enumeration type):
typedef enum {
LEPT_NULL,
LEPT_FALSE,
LEPT_TRUE,
LEPT_NUMBER,
LEPT_STRING,
LEPT_ARRAY,
LEPT_OBJECT
} lept_type;
JSON It's a tree structure , We finally need to implement a tree data structure , Each node uses lept_value The structure represents , We'll call it a JSON value (JSON value).
typedef struct {
lept_type type;
}lept_value;
We only need two now API function , One is parsing JSON:
int lept_parse(lept_value* v, const char* json);
The return values are the following enumerated values , No error will be returned LEPT_PARSE_OK.
enum {
LEPT_PARSE_OK = 0,
LEPT_PARSE_EXPECT_VALUE,
LEPT_PARSE_INVALID_VALUE,
LEPT_PARSE_ROOT_NOT_SINGULAR
};
- If one JSON Contains only white space , Send back LEPT_PARSE_EXPECT_VALUE.
- If after a value , There are other characters after whitespace , Send back LEPT_PARSE_ROOT_NOT_SINGULAR.
- If the value is not the three literal values , Send back LEPT_PARSE_INVALID_VALUE.
Now we only need a function to access the result , Is to get its type :
lept_type lept_get_type(const lept_value* v);
To reduce the number of arguments passed between analytic functions , We put json Put all the data into one lept_context Structure :
typedef struct {
const char* json;
}lept_context;
边栏推荐
- 2021-03-23
- JS function to realize simple calculator
- API interface management setup -eolinker4.0
- CUDA compilation error
- Five simple data types of JS
- Difference between asemi high power FET and triode
- Student achievement management system based on SSH
- How to install the blue lake plug-in to support Photoshop CC 2017
- Even if you are not good at anything, you are growing a little bit [to your 2021 summary]
- hr竟主动给这位测试小姐姐涨工资,她是怎么做到的?
猜你喜欢
Matlab notes
A review of small sample learning
Extend the toolbar of quill editor
[relax's law of life lying on the square] those poisonous chicken soup that seem to be too light and too heavy, but think carefully and fear
Professional things use professional people
Summary of SQL injection (I)
Penetration test - right raising topic
How to install the blue lake plug-in to support Photoshop CC 2017
Svg code snippet of loading animation
Kotlin compose perfect todo project surface rendering background and shadow
随机推荐
Handwritten promise all
What is Ethernet and how to connect the computer
Activereportsjs V3.0 comes on stage
Create dynamic array
Personalized Federated Learning with Moreau Envelopes
Google Earth engine (GEE) - Global jrc/gsw1_ 1 / batch download of yearlyhistory dataset (China region)
Filter & listener (XIV)
Go deep into the working principle of browser and JS engine (V8 engine as an example)
Compatible with Internet Explorer
Baidu ueeditor set toolbar initial value
Swift rapid development
Basic bit operation symbols of C language
Svg code snippet of loading animation
Matlab notes
CSRF (Cross Site Request Forgery) &ssrf (server request forgery) (IV)
Summary of SQL injection (I)
Implementation of websocket long connection by workman under laravel
Create an environment for new projects
IronOCR 2022.1 Crack
Penetration test - right raising topic