【发布时间】:2016-12-09 01:50:09
【问题描述】:
我正在 swift 3 中编写代码,用于解析来自 http 请求的 json 格式结果的查询。
json格式为:
JSON: {
base = stations;
coord = {
lat = "23.9";
lon = "42.89";
};
weather = (
{
description = mist;
icon = 50n;
id = 701;
main = Mist;
},
{
description = fog;
icon = 50n;
id = 741;
main = Fog;
}
);
wind = {
deg = "222.506";
speed = "1.72";
};}
我的代码是:
Alamofire.request(url).responseJSON { response in
if let a = response.result.value {
let jsonVar = JSON(a)
if let resDati = jsonVar["base"].string {
print(resDati as String) // <- OK
}
if let dati2 = jsonVar["weather"].array {
for item in dati2 {
print(" > \(item["main"])") // <- OK
}
}
} else {
print(Error.self)
}
}
问题在于我尝试过的“坐标”和“风”数据:
if let dati4 = jsonVar["wind"].array {
for item in dati4 {
print("-- \(item)")
} }
我无法以 json 格式打印与“wind”和“coord”相关的数据。
我该如何解决这个问题。
谢谢。
【问题讨论】:
标签: ios json swift3 xcode8 swifty-json