gpt4 book ai didi

json - SWIFT 2 - alamofire - 解析 JSON 参数

转载 作者:行者123 更新时间:2023-11-30 13:57:53 26 4
gpt4 key购买 nike

我正在尝试使用 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; }

现在,我如何调用参数“name”?

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

最佳答案

 print("Response data: \(JSON[1]["Name"] as! String)")

关于json - SWIFT 2 - alamofire - 解析 JSON 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com