Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unescaped control character around character 981.Error while parsing JSON

Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character
around character 981." UserInfo={NSDebugDescription=Unescaped control
character around character 981.}

I am getting the above error in response to a request.

Below are the lines of code:

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)
    }
}

It gives a JSON response in Postman.

The response which is I am getting in Postman:

{
  "orderdetails": {
    "status_code": "200",
    "status_message": "Order details",
    "billingandshipping": {
      "billing": {
        "firstname": "first",
        "lastname": "last",
        "email": "[email protected]",
        "address": "dasdesfrew",
        "city": "Rajkot",
        "area": "University Road",
        "pincode": "360003",
        "phone": "1234567890",
        "mobileno": "1234567891"
      },
      "shipping": {
        "firstname": "first",
        "lastname": "last",
        "email": "[email protected]",
        "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.."
      }
    ]
  }
}
like image 343
Payal Maniyar Avatar asked Aug 31 '16 11:08

Payal Maniyar


1 Answers

As per you were told, there is a problem related to "\n".

So I suggest you can add "" which will work for you, like below:

"\n"=> "\\n"

Because this is a special character called a backspace character.

like image 63
Ashish Gondaliya Avatar answered Sep 30 '22 14:09

Ashish Gondaliya