Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在数组中查找名称(JSON)_Swift - Fatal编程技术网

Swift 在数组中查找名称(JSON)

Swift 在数组中查找名称(JSON),swift,Swift,如何知道此数组是否包含名称“test” 如果json是数组 [{ "participantId" : 1, "player" : { "summonerName" : "8eautiful", } }, { "participantId" : 2, "player" : { "summonerName" : "test", } }] 到目前为止你尝试了什么?您应该使用Codable而不是SwiftyJSON。 for (index,subJson):(S

如何知道此数组是否包含名称“test”


如果json是
数组

[{
  "participantId" : 1,
  "player" : {
    "summonerName" : "8eautiful",
  }
},
{
  "participantId" : 2,
  "player" : {
    "summonerName" : "test",
  }
}]

到目前为止你尝试了什么?您应该使用
Codable
而不是
SwiftyJSON
for (index,subJson):(String, JSON) in json {
    if subJson["player"]["summonerName"] == "test" {
        print("Array contains the name test")
    } else {
        print("Array does not contain the name test")
    }
}