首页 > 解决方案 > 在数组中查找名称 (JSON)

问题描述

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

你怎么知道这个数组是否包含名称“test”?

使用 swiftyjson

标签: swift

解决方案


如果 json 是一个Array

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")
    }
}

推荐阅读