我是GO的新手,我想將json從facebook api轉換為struct。問題在于對象的鍵是動態的:{ "100555213756790": { "id": "100555213756790", "about": "Noodle Bar & Restaurant", "metadata": { "fields": [ { "name": "id", "description": "asdasdasdasd", "type": "numeric string" }, //... , "101285033290986": { "id": "101285033290986", "about": "Smart City Expo World Congress", "metadata": { "fields": [ { "name": "id", "description": "fgddgdfgdg", "type": "numeric string" },到目前為止,我所實現的是通過id提取對象并將其轉換為地圖:for _, id := range ids { fbPages, ok := results[string(id)].(map[string]interface{}) if ok { for k, v := range fbPages { fmt.Println(k) fmt.Println(v) } }}//json to Page struct? type Page struct { ID string `json:"id"` About string `json:"about"` } type Metadata struct { Fields []Field `json:"fields"` Type string `json:"type"` Connections map[string]string `json:"connections"` } type Field struct { Name string `json:"name"` Description string `json:"description"` Type *string `json:"type,omitempty"` }我的問題是:如何將該映射轉換為struct?還是有什么簡單的方法可以做我想做的事情?
- 1 回答
- 0 關注
- 284 瀏覽
添加回答
舉報
0/150
提交
取消