我正在使用带有参数和标头的Alamofire进行获取请求,我想要一个格式正确的json,但我没有得到它。 如何处理从服务器返回的响应JSON?
我的代码
var params: Parameters = [
"current_facility_id": "*****************",
"current_user_id": "*******************\",
"current_date": "\(current_date)"
]
let defaults = UserDefaults.standard
let token = defaults.string(forKey: "token")
var headers: HTTPHeaders = [
"token": token!
]
Alamofire.request(opd_appointments_list, method: .get, parameters: params, encoding: URLEncoding.queryString, headers: headers).responseJSON { (response) in
print("Hurray...... Got the data.... ")
if let data = response.result.value as? Dictionary<String, Any> {
print(data)
}
}
这在我的控制台中以json.result.value的形式显示。
我在邮递员中使用相同的URL响应json。
{
"tabs": 5,
"REFERRAL": [],
"COMPLETED": [],
"ALL": [
{
"state": "doctor",
"patient_id": "5b4c307ccd29ba3dfe5355cd",
"display_id": "JAL-OPD-204441",
"id": "5b4c307ccd29ba3dfe5355de",
"doctor": "578f0cb0666d673609000018",
"appointmentdate": "16 Jul,18",
"borderColor": "#ff0000",
"appointment_booked_type": "Post OP Patient",
"backgroundColor": "#ff0000",
"title": "narender singh",
"end_time": null,
"start_time": "11:13 AM",
"current_user_id": "578f0cb0666d673609000018",
"with_user": "HgDummyDoc",
"workflow_id": "5b4c307ccd29ba3dfe5355e0",
"doctor_ids": [
"578f0cb0666d673609000018"
],
"time_difference": "1 hr 49 mins",
"referral": false,
"referring_doctor": "",
"dilation_state": null,
"dilation_state_color": null,
"dilation_start_time": null,
"dilation_end_time": null,
"ophthal_assessment": false,
"workflow_state": null
}
],
"MY_QUEUE": [],
"NOT_ARRIVED": []}