donglang6656 2017-08-12 17:49
浏览 26
已采纳

如何构造界面? [关闭]

I have this json array and I need to extract the data:

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

How can I structure the interface?

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

f = map[string]interface{}{

----> ?

}
  • 写回答

1条回答 默认 最新

  • doufang2228 2017-08-12 19:47
    关注

    Is this what you are looking for?

    You can test the code 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)
    }
    

    For details see the comments in the code. Feel free to ask.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致