从服务器响应中快速获取价值



我是 Swift 的新手, 我想从服务器响应中获取纬度和长度的值。

如何获取值?

这是我的代码:

WebServiceHelper.sharedInstance.makeWebServiceCall(urlAddress: "http://jsonplaceholder.typicode.com/users/1", requestMethod: "GET", params: ["Key" : "value"], Success: { (JSON:Any) in
print("Success Received data is: (JSON)")
}, Error: { (JSON:Any) in
print("Error Received data is: (JSON)")
}) { (JSON:Any) in
print("Header Received data is: (JSON)")
}

我能够得到服务器回复这里是:

Success Received data is: {
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"latitude": "-37.3159",
"longitude": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}

我怎么得到?

你可以这样尝试得到纬度长:

if let result = JSON as? [String:AnyObject]{
let address = result?["address"] as? [String:AnyObject]
let geo = address?["geo"] as? [String:AnyObject]
print(geo?["lng"])
print(geo?["lat"]) }

相关内容

  • 没有找到相关文章

最新更新