I have a weird setup where I am trying to parse a dictionary of an array of dictionaries.
How is this parsed in Swift?
I get the json object as below, but now sure how to proceed.
if let earthquake_data = json as? NSDictionary {
}
-
{
"earthquakes": [
{
"datetime": "2011-03-11 04:46:23",
"depth": 24.4,
"lng": 142.369,
"src": "us",
"eqid": "c0001xgp",
"magnitude": 8.8,
"lat": 38.322
},
{
"datetime": "2015-04-25 06:13:40",
"depth": 15,
"lng": 84.6493,
"src": "us",
"eqid": "us20002926",
"magnitude": 7.9,
"lat": 28.1306
},
I recommend to use this library to parse JSON on Swift: https://github.com/SwiftyJSON/SwiftyJSON
Example:
if let earthquake_data = JSON(json){
let dateTime = earthquake_data["earthquakes"][0][datetime].stringValue
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.