2017-08-12 71 views
-5

我有这个JSON数组,我需要提取数据:如何构造界面?

b := [[{"client": " 321"}], [{"number": "3123"}]] 

我怎么能结构的界面?

var f interface{} 
err := json.Unmarshal(b, &f) 

f = map[string]interface{}{ 

----> ? 

} 
+0

https://gobyexample.com/json – RayfenWindspear

+0

您可以根据需要构造它。你想解决什么问题? – Flimzy

回答

0

这是你在找什么?您可以测试代码here

package main 

import (
    "encoding/json" 
    "fmt" 
    "log" 
) 

func main() { 
    // test input (json.Unmarshal expects []byte) 
    b := []byte("[[{\"client\": \" 321\"}], [{\"number\": \"3123\"}]]") 

    // declare the target variable in the correct format 
    var f [][]map[string]string 

    // unmarshal the json 
    err := json.Unmarshal(b, &f) 
    if err != nil { 
     // handle error 
     log.Fatal(err) 
    } 

    // output result 
    fmt.Println(f) 
} 

有关详细信息,请参阅代码中的注释。随意问。

+0

我不知道如何访问数据,并认为它必须通过一个结构来完成。您的回答帮助我了解我所寻找的内容 fmt.Println(f [0] [0] [“client”])-----> 321 fmt.Println(f [1] [0] [“号码]] -----> 3123 非常感谢! –