在解析JSON时,字符981.Error周围的非转义控制字符 [英] Unescaped control character around character 981.Error while parsing JSON
问题描述
错误域= NSCocoaErrorDomain代码= 3840未转义的控制字符
围绕字符981。 UserInfo = {NSDebugDescription =未转义控制字符981周围的
字符。}
Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 981." UserInfo={NSDebugDescription=Unescaped control character around character 981.}
我在响应请求时遇到上述错误。
I am getting above error in response of request.
以下是代码行:
Alamofire.request(.POST, urlStr, parameters: parameter, encoding: .JSON, headers: nil).validate().responseJSON {
response in switch response.result {
case .Success(let JSON):
completionHandler(JSON as! NSDictionary)
case.Failure(let Error):
print(Error)
}
}
它在Postman中提供JSON响应。
It gives JSON response in Postman.
我在Postman中得到的回应:
Response which is I am getting in Postman:
{
"orderdetails": {
"status_code": "200",
"status_message": "Order details",
"billingandshipping": {
"billing": {
"firstname": "first",
"lastname": "last",
"email": "aa@bbb.com",
"address": "dasdesfrew",
"city": "Rajkot",
"area": "University Road",
"pincode": "360003",
"phone": "1234567890",
"mobileno": "1234567891"
},
"shipping": {
"firstname": "first",
"lastname": "last",
"email": "aa@bbb.com",
"address": "dasdesfrew",
"city": "dasdesfrew",
"area": "dcdc",
"pincode": "360003",
"phone": "1234567890",
"mobileno": "1234567891"
}
},
"orders": [
{
"order_id": "77",
"order_date": "09-08-2016 13:05:29",
"delivery_date": "10-08-2016",
"order_items": [
{
"Sr": "1",
"product_name": "Lemon",
"gujtitle": "લીંબુ ",
"product_code": "000057",
"product_price": "108.00",
"product_qty": "2",
"unit": "1 kg.",
"product_total": "216"
}
],
"final_total": "216.00",
"shipping_cost": "0.00",
"order_total": "216.00",
"discount_type": "null",
"discount_amount": "null",
"coupon_name": "null",
"comment": "gdhdj\nfghd.g\nghj\n\n\n\n\n\n\n\n\n\n.."
}
]
}
}
推荐答案
As你告诉我有与\ n有关的问题
As per you told there is problem related to "\n"
所以我建议你可以添加\,这对你有用,如下所示
So i suggest you can add "\" which will work for you like below
\ n=>\\ n
因为这是特殊的字符调用退格符。
Because this are special character call backspace character.
希望得到答案
这篇关于在解析JSON时,字符981.Error周围的非转义控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!