当前位置:网站首页>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;边栏推荐
- Go deep into the working principle of browser and JS engine (V8 engine as an example)
- February 20ctf record
- How to choose the years of investment in financial products?
- Implementation of websocket long connection by workman under laravel
- 2021-10-24
- ThinkPHP 5 log management
- Svg code snippet of loading animation
- Difference between asemi high power FET and triode
- Visual studio 2022 interface beautification tutorial
- Understand JS high-order function and write a high-order function
猜你喜欢
![[Huawei machine test] hj16 shopping list](/img/54/d28f5aea9350af7797ca7c069e564d.jpg)
[Huawei machine test] hj16 shopping list

Detailed summary of flex layout

Array: force deduction dichotomy

Kotlin compose listens to the soft keyboard and clicks enter to submit the event

Dynamic programming example 2 leetcode62 unique paths

Two hours to take you into the software testing industry (with a full set of software testing learning routes)

Extend the toolbar of quill editor

Various pits encountered in the configuration of yolov3 on win10

Flex flexible layout for mobile terminal page production

Specific operations for uploading pictures in PHP
随机推荐
Swift rapid development
Basic knowledge of web pages (URL related)
Makefile Foundation
File upload vulnerability (III)
A review of small sample learning
Try block and exception handling
How to open the DWG file of the computer
Array and simple function encapsulation cases
Redis (17)
Introduction to the hardest core PWN in the whole network_ Graphic analysis
PHP uses JWT
Enhanced paste quill editor
Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').
【FLink】access closed classloader classloader. check-leaked-classloader
Abuse unlimited authorization -- is your address safe?
Even if you are not good at anything, you are growing a little bit [to your 2021 summary]
Essais de pénétration - sujets d'autorisation
CSRF (Cross Site Request Forgery) &ssrf (server request forgery) (IV)
Student achievement management system based on SSH
2021-10-24