如何解组 json 数组?

当我解组 json 数组时出现问题。

我该如何纠正?代码是:http : //play.golang.org/p/AtU9q8Hlye


package main


import (

    "encoding/json"

    "fmt"

)


type Server struct {

    ServerName string

    ServerIP   string

}


type Serverslice struct {

    Name    string

    Servers []Server

}


func main() {

    var s []Serverslice

    str := `{"name":"dxh","servers":[{"serverName":"VPN0","serverIP":"127.0.0.1"},{"serverName":"Beijing_VPN","serverIP":"127.0.0.2"}],

        "name":"dxh1,"servers":[{"serverName":"VPN1","serverIP":"127.0.0.1"},{"serverName":"Beijing_VPN","serverIP":"127.0.0.2"}]}`


    json.Unmarshal([]byte(str), &s) //the wrong line.....................

    fmt.Println(len(s))

}


慕码人8056858
浏览 162回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go