1

我如何获得已玩比赛和得分的价值?我不知道如何用这种结构检索 Json 数据。

lifeTimeStats =     (
        {
            key = "Matches Played";
            value = 764;
        },
        {
             key = Score;
             value = "126,830";
            }
        );
4

1 回答 1

1

你可以试试,我希望你有那个json的数据

do {

     var json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String:Any]

     if let current = json["lifeTimeStats"] as? [Any] {
        if let Key_value = current[0] as? [String : Any] {
           if let Score_String = Key_value["key"] as? String {
             self.Score.text = Score_String
           }
        }
      }  
   }
 catch let err as NSError {
    print(err)
  }
于 2018-05-03T18:28:25.597 回答