目前遇到一問題,如何從
map[string]interface{} 裡面內容如: {"a":92, "b":{"c": "123", "d": 1235}}
取得c的資料
一般取外層b都很簡單,但是要再往下一層取就會遇到問題
type interface {} does not support indexing
其解決方法很簡單,因為內層架構跟外層架構是一樣的
map[a:92 b:map[c:123 d:1235]]
所以往下一層前記得重新轉型一次就行了
var result map[string]interface{}
json_body := []byte(`{"a":92, "b":{"c": "123", "d": 1235}}`)
json.Unmarshal(json_body, &result)
fmt.Println(result)
fmt.Println("============")
bResult := result["b"].(map[string]interface{})
fmt.Println("c: " + bResult["c"].(string))
文章標籤
全站熱搜