1 回答
TA贡献1155条经验 获得超0个赞
根据评论中的建议,我复制了您的方案,如下所示:
package main
import (
"encoding/json"
"fmt"
"log"
"reflect"
)
type Data struct {
TaiList []Tai `json:"taiList"`
}
type Tai struct {
PlmnId *PlmnId `json:"plmnId"`
Tac string `json:"tac"`
Nid string `json:"nid"`
}
type PlmnId struct {
Mcc string `json:"mcc"`
Mnc string `json:"mnc"`
}
var data = []byte(`{
"taiList": [
{
"plmnId": {
"mcc": "244",
"mnc": "24"
},
"tac": "00001",
"nid": "99"
},
{
"plmnId": {
"mcc": "244",
"mnc": "34"
},
"tac": "00001",
"nid": "555"
}
]
}
`)
var ta = Tai{
PlmnId: &PlmnId{Mcc: "244", Mnc: "34"},
Tac: "00001",
Nid: "555",
}
func CheckTai(ta Tai, data Data) bool {
for _, Tai := range data.TaiList {
if reflect.DeepEqual(Tai, ta) {
return true
}
}
return false
}
func main() {
var v Data
err := json.Unmarshal(data, &v)
if err != nil {
log.Fatal(err)
}
fmt.Println(CheckTai(ta, v))
}
输出:
true
- 1 回答
- 0 关注
- 59 浏览
添加回答
举报