This my json.file:
[
{
"date_range": "2016-11-01-2016-12-31",
"order_status_id": 3,
"jobs": [
{
"date": "2016-11-14",
"job": [
{
"id": 143608,
"pickup_worker_id": null,
"drop_off_worker_id": 57
}
]
}
]
}
{
"date_range": "2016-11-01-2016-12-31",
"order_status_id": 2,
"jobs": [
{
"date": "2016-11-16",
"job": [
{
"id": 143238,
"pickup_worker_id": null,
"drop_off_worker_id": 12
},
{
"id": 13218,
"pickup_worker_id": null,
"drop_off_worker_id": 42
}
]
},
{
"date": "2016-11-19",
"job": [
{
"id": 141238,
"pickup_worker_id": null,
"drop_off_worker_id": 12
}
]
}
]
}
]
This my code for swiftyjson
:
Alamofire.request(Constants.web_api+api_get_orders, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: Constants.headers ).responseJSON { (responseData) -> Void in
if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)
print("All Data JSON \(swiftyJsonVar)")
print("date range1\(swiftyJsonVar["date_range"])")
print("date range2\(swiftyJsonVar["date_range"].stringValue)")
print("jobs1 \(swiftyJsonVar["jobs"].arrayObject)")
print("jobs2 \(swiftyJsonVar["jobs"].array)")
print("jobs3 \(swiftyJsonVar["jobs"])")
print("jobs date \(swiftyJsonVar["jobs"]["date"].stringValue)")
print("jobs date \(swiftyJsonVar["jobs"]["job"]["drop_off_worker_id"].stringValue)")
}
The output , all is null or nil except All Data JSON (swiftyJsonVar
). How can I get value of date_range
, drop_off_worker_id
? I really hope someone can help me. I spend a lot of time for solve it but still can't solve it.
Your JSON response is
Array
notDictionary
, so you need to access its first object to get the detail you want.Edit: If you have multiple object in your root than get all the
dateRange
andworker_id
in for loop.