ios - NSJSONSerialization converting NSDictionary to Hexadecimal -


im attempting convert nsdictionary json using nsjsonserialization.datawithjsonobeject function

code :

do{     let jsondata = try nsjsonserialization.datawithjsonobject(serializationhelper.todictionary(user), options: nsjsonwritingoptions.prettyprinted )      print(jsondata)     } catch {          print(error)     } 

all except jsondata being printed in hexadecimal?

<7b0a2020 22706173 73776f72 6422203a 20227465 7374222c 0a202022 75736572 6e616d65 22203a20 22546573 74220a7d> 

when hexadecimal string converted binary infact equal json object need json object straight away.

any ideas why case?

you 1 step away solution:

swift 3:

let jsondata = try jsonserialization.data(withjsonobject: dictionary, options: .prettyprinted) let jsonstring = string(data: jsondata, encoding: .ascii) print("json string = \(jsonstring!)") 

swift 2:

let jsondata = try nsjsonserialization.datawithjsonobject(dictionary, options: .prettyprinted ) let jsonstring = string(data: jsondata, encoding: nsasciistringencoding) print("json string = \(jsonstring!)") 

both examples should wrapped do-catch


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -