[Super detailed] Writing format, parsing and usage of Json in vscode

1: Serialization and deserialization

Serialization: The process of converting an object into a sequence of bytes
Deserialization : The process of restoring a byte sequence into an object
Note: All serialization and deserialization operations are attribute-based and have nothing to do with type behavior.
Purpose : persistence (persistence is the attribute of this type)
(For example: photos and images are left, but they cannot show many events in growth)
High-level languages: object-oriented, process-oriented, object-based
Format : xml, Json (represents Javascript  object but Javascript  does not have new object language, so I came up with json string)
Structure : key-value pair structure
Advantages: Can represent very complex data

2: Json syntax

1: Punctuation marks

{ } indicates that this is an object of type
[ ] represents an array or collection
: Used to separate keys and values
" " is used in attribute names
, each key-value pair is separated by a comma ( the last key-value pair has no comma )

2: Attribute value types allowed by Json

string        √               char×
Integer Decimal √ 
bool          √
Array, set√
Custom type√
Note: green wavy lines represent syntax errors

3: Small exercises (1)

Step 1: Write a Json file. You can write it in document txt first, and then change the suffix to json.

Step 2: Add reference to C# script
in +using Newtonsoft.Json ;
Step 3: Create the class
NOTE: Right click on the json file and always copy

 

The json file and the above attributes must correspond one-to-one

Supplementary writing summary: (First fold, look at the brackets, and write from the inside to the outside)

The first:

 

The second type:

The third type:

 

Step 4: Analysis
Corresponding to the first type above:

 Corresponding to the second type above:

  Corresponding to the third type above: [  The object contains a collection, so another class needs to be written]

 Because there is a collection, stringbuilder is used

Notice:
1: Matching class:
When declaring a type, all attribute names in json and the attribute names in the class must be consistent.
2: The abstract method is not in the ordinary class and cannot match json parsing. Use virtual methods.
4: Small exercises (2)
If there is a collection name in the file:
(Note: Not all class libraries can parse double using float )
1 First create the tank class and then write a class class
2Declare a collection
If there is no collection name in the file:
1 First write a weapon class
2 Store directly in the main function

Guess you like

Origin blog.csdn.net/m0_74022070/article/details/130235255