0

When i get results from web Service JSON comes like this :

responseString = "\{\\\"code\\\":\\\"OK\\\",\\\"description\\\":\\\" DOĞRULAMA KODUNUZ 6806\\\"}\"

but When I print it.

let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
            print("responseString = \(responseString)")

I see this response:

responseString = Optional("{\"code\":\"OK\",\"description\":\"DOĞRULAMA KODUNUZ 6806\"}")

And i want to parse it. But I get format error. My code is below:

let responseJson = JSONStringify(responseString!)
let json: AnyObject? = responseJson.parseJSONString

let code = (json as! NSDictionary)["code"] as! String

let description = (json as! NSDictionary)["description"] as! String 
print("code: \(code)")
print("description: \(description)")

Thank you for your help.

slytrkmn
  • 272
  • 1
  • 4
  • 15
  • I know it is not valid JSON. I want to convert this one to valid JSON. They use C# for backend. When I talk with backend developer he says he cant change it. Thank you for your help – slytrkmn Aug 01 '16 at 13:01
  • Take your Optional "responseString", unwrap it and use the function in the linked answer. No need for any JSONStringify or weird castings. – Eric Aya Aug 02 '16 at 11:35

0 Answers0