【问题标题】:SWIFT 2 - alamofire - Parsing JSON parametersSWIFT 2 - alamofire - 解析 JSON 参数
【发布时间】:2015-10-27 17:10:54
【问题描述】:

我正在尝试使用 Alamofire 调用 JSON 数组中的对象。 我可以让 Alamofire 解析我的文件,但是我找不到获取特定参数的方法。

如果我使用:

Alamofire.request(.GET, "https://example.com//users_result.json")
            .responseJSON { response in

                print(response.result)   // result of response serialization

                if let JSON = response.result.value {
                    print(JSON.count)
                    print("JSON: \(JSON[1])")
                }
        }

代码打印出来:

> SUCCESS 4 JSON: {
>     Age = 22;
>     Email = "annahswift@gmail.com";
>     Location = "New York";
>     MyText = "Love Music";
>     Name = Annah;
>     Password = 123456;
>     REF = 003;
>     "Reg_Date" = "2015-07-30";
>     Sex = Female;
>     Surname = Swift; }

现在,如何调用参数“名称”?

print("JSON: \(JSON[1][4])") // nil ??

【问题讨论】:

标签: json swift alamofire


【解决方案1】:
 print("Response data: \(JSON[1]["Name"] as! String)")

【讨论】:

  • 你必须转义引号,不是吗?或者放在单独的语句中。
  • @Rob Depends:自 Xcode 7.1 beta 3 以来,我们不必再逃跑了。
猜你喜欢
  • 2020-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-22
  • 2018-11-12
相关资源
最近更新 更多