如何正确解析 json 我有以下 json 文件{    "hello": {        "title": "Golang",        "story": [            "Go lang story",            "Channel story"        ],        "options": [            {                "text": "That story",                "arc": "west"            },            {                "text": "Gee",                "arc": "east"            }        ]    },    "world": {        "title": "Visiting",        "story": [            "Boo",            "Doo",            "Moo",            "Qoo"        ],        "options": [            {                "text": "weird",                "arc": "west"            },            {                "text": "funny",                "arc": "north"            }        ]    }}我为内部创建了这些结构type chapter struct{    Title string `json:"title"`    Story []string `json:"story"`    Option []option `json:"options"`}type option struct {    Text string `json:"text"`    Arc string `json:"arc"`}但我不知道如何解析像“hello”和“world”这样的包装器
                    
                    
                1 回答
 
                    
                    
                            繁花不似锦
                            
                                
                            
                        
                        
                                                
                    TA贡献1851条经验 获得超4个赞
您需要做的就是构建根映射。
{
    "hello":{},
        "world":{}
}这里的hello和world也在地图内。所以你也需要构建它们。
var root map[string]chapter json.Unmarshal(JSONDATA,&root)
- 1 回答
- 0 关注
- 121 浏览
添加回答
举报
0/150
	提交
		取消
	