当前位置:网站首页>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;边栏推荐
猜你喜欢

Example of dynamic programming 3 leetcode 55

Compatible with Internet Explorer

Use js to simply implement the apply, call and bind methods

A review of small sample learning

CTFHUB SSRF

Working principle of asemi three-phase rectifier bridge

渗透测试-目录遍历漏洞

Essais de pénétration - sujets d'autorisation

Use serialize in egg to read and write split tables

Route parameters to jump to the page and transfer parameters -- > hidden parameter list
随机推荐
Abuse unlimited authorization -- is your address safe?
Rce code execution & command execution (V)
Laravel Aurora push
Characteristics of ES6 arrow function
投资理财产品的年限要如何选?
How to open the DWG file of the computer
【FLink】access closed classloader classloader. check-leaked-classloader
February 19 CTF exercise
Introduction to the hardest core PWN in the whole network_ Graphic analysis
February 20ctf record
Detailed summary of float
Activereportsjs V3.0 comes on stage
Database query optimization method
Implementation of websocket long connection by workman under laravel
Could not find “store“ in the context of “Connect(homePage)
Large number operation (capable of square root, power, permutation and combination, logarithm and trigonometric value)
Detailed summary of position positioning
渗透测试-目录遍历漏洞
Fundamentals of C language
Eyeshot Ultimate 2022 Crack By Xacker