构建JSON数据结构同时, 返回字段类型以及示例值
This commit is contained in:
@ -125,3 +125,45 @@ func TestParse(t *testing.T) {
|
||||
byteData, _ := json.Marshal(source)
|
||||
fmt.Println(GetJSONDataStruct(string(byteData)))
|
||||
}
|
||||
|
||||
// TestParseWithType 测试获取JSON数据结构
|
||||
//
|
||||
// Author : go_developer@163.com<张德满>
|
||||
//
|
||||
// Date : 10:59 PM 2022/1/9
|
||||
func TestParseWithType(t *testing.T) {
|
||||
source := map[string]interface{}{
|
||||
"name": "zhangdeman",
|
||||
"extra": map[string]interface{}{
|
||||
"age": 18,
|
||||
"height": 180,
|
||||
"slice": []int{1, 2, 3},
|
||||
"obj": map[string]interface{}{
|
||||
"la": "aaaa",
|
||||
},
|
||||
},
|
||||
"slice": []int{1, 2, 3},
|
||||
"map": map[string]interface{}{"a": 1, "d": 5.5, "e": "qqq"},
|
||||
"empty_obj": map[string]interface{}{},
|
||||
"empty_list": make([]interface{}, 0),
|
||||
"table": []map[string]interface{}{
|
||||
{"name": "alex", "age": 18, "number": 1, "obj": map[string]interface{}{"enen": "en"}},
|
||||
{"name": "bob", "age": 28, "number": 2},
|
||||
},
|
||||
"two_slice": []map[string]interface{}{
|
||||
{
|
||||
"students": []map[string]interface{}{
|
||||
{
|
||||
"name": "enen",
|
||||
"age": 18,
|
||||
"score": []float64{1, 2, 3, 45},
|
||||
},
|
||||
},
|
||||
"other": []interface{}{"others"},
|
||||
"read_only": 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
byteData, _ := json.Marshal(source)
|
||||
fmt.Println(GetJSONDataStructWithType(string(byteData)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user