【the waiter】announcement:
Json to struct
| | |
feature introduction
- Support parsing nested json strings and parsing nested objects according to recursion
- Parsing array json string is supported. The first json string in the array will be parsed.
- Support for injection of custom tag
- Check whether the format of the json string is correct and the location of the output error
example
parsing nested json strings
{
"name": "test",
"age": 10,
"addr": "Sichuan Chengdu",
"cls_info": [
{
"name": "basketball class",
"teacher": "Mr. Zhang"
}
{
"name": "Art Class",
"teacher": "Miss Li"
}
]
}
After treatment
type GenerateStruct struct {
Name string `json: "name,omitempty"`
Age int `json: "age,omitempty"`
Addr string `json: "addr,omitempty"`
ClsInfo [] ClsInfo `json: "cls_info,omitempty"`
}
type ClsInfo struct {
Name string `json: "name,omitempty" `
Teacher string `json: "teacher,omitempty" `
}
parsing array json strings directly
[
{
"name": "test",
"age": 10,
"addr": "Sichuan Chengdu",
"cls_info": [
{
"name": "basketball class",
"teacher": "Mr. Zhang"
}
{
"name": "Art Class",
"teacher": "Miss Li"
}
]
}
{
"name": "test2",
"age": 10,
"addr": "Sichuan Chengdu",
"cls_info": [
{
"name": "basketball class",
"teacher": "Mr. Zhang"
}
{
"name": "Art Class",
"teacher": "Miss Li"
}
]
}
]
After treatment
type GenerateStruct struct {
Name string `json: "name,omitempty"`
Age int `json: "age,omitempty"`
Addr string `json: "addr,omitempty"`
ClsInfo [] ClsInfo `json: "cls_info,omitempty"`
}
type ClsInfo struct {
Name string `json: "name,omitempty" `
Teacher string `json: "teacher,omitempty" `
}