当前位置:网站首页>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;边栏推荐
- Page electronic clock (use js to dynamically obtain time display)
- IronOCR 2022.1 Crack
- Dynamic programming example 1 leetcode 322 coin change
- CTFHub-rce
- Electric store stores data
- Visual studio 2022 interface beautification tutorial
- Array and simple function encapsulation cases
- Enhanced paste quill editor
- 渗透测试-目录遍历漏洞
- Detailed summary of float
猜你喜欢

What is Ethernet and how to connect the computer

Ctfhub eggs

File upload vulnerability (III)

Detailed summary of float
![[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](/img/12/d41f8d5abcb61d2632a8b117bf1604.jpg)
[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

Reading and writing of nodejs excel (.Xlsx) files

Go deep into the working principle of browser and JS engine (V8 engine as an example)

Qdebug June 2022

Small sample learning data set

buuctf(re)
随机推荐
Rce code execution & command execution (V)
[keil] GPIO output macro definition of aducm4050 official library
Laravel Vonage SMS sending
Try block and exception handling
Using JS to realize the sidebar of life information network
Go Context - Cancelation and Propagation
Database overview
Uva1103 ancient pictograph recognition
The article is on the list. Welcome to learn
Extend the toolbar of quill editor
Use serialize in egg to read and write split tables
Two hours to take you into the software testing industry (with a full set of software testing learning routes)
SQL lab range explanation
Essais de pénétration - sujets d'autorisation
How to make colleagues under the same LAN connect to their own MySQL database
Summary of SQL injection (I)
Swift rapid development
February 19 CTF exercise
What if win11 Bluetooth fails to connect? Solution of win11 Bluetooth unable to connect
Go Methods and Interfaces