我是Swift新手, 我想從服務器響應中獲取緯度和longitde的值。從服務器響應中獲取價值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": "[email protected]",
"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"
}
}
我如何獲得?
JSONSerialization,之後轉換成你的模型 –
檢查這個問題https://stackoverflow.com/questions/45019869/what-am -i-doing-wrong-in-my-json-post/45020163#45020163 –
你可以幫我理解語法嗎? –