亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Golang Facebook對結構的回應

Golang Facebook對結構的回應

Go
叮當貓咪 2021-04-05 13:18:12
我是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 回答

  • 1 回答
  • 0 關注
  • 284 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號