Van Fury
unread,May 24, 2021, 11:44:34 AM5/24/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hi,
I have an array of JSON objects as
Structs:
```
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"`
}
```
The JSON is of the form
```
{
"taiList": [
{
"plmnId": {
"mcc": "244",
"mnc": "24"
},
"tac": "00001",
"nid": "99"
},
{
"plmnId": {
"mcc": "244",
"mnc": "34"
},
"tac": "00001",
"nid": "555"
}
]
}
```
I would like to check if the JSON object "ta" is contain in the "taiList".
```
var ta = model.Tai{
PlmnId: &model.PlmnId{Mcc: "244", Mnc: "34"},
Tac: "00001",
Nid: "555",
}
```
I tried with the code below
```
func CheckTai(tai model.Tai, TaiList []model.Tai) bool {
for _, Tai := range TaiList {
if reflect.DeepEqual(Tai, tai) {
return true
}
}
return false
}
```
but CheckTai function return false.
The CheckTai only return true when there is only one JSON object that match the list as
```
{
"taiList": [
{
"plmnId": {
"mcc": "244",
"mnc": "24"
},
"tac": "00001",
"nid": "555"
}
]
}
```
Need help or idea on how to perform this check.