Swift3 Array convert in String like "{\"type\": \"0\"}" -
i have created 1 array in swift. have 1 node.js api, in api passing string type data
let dic = "{\"type\": \"0\",\"message\": \"\(message)\", \"sender_id\":\"\(username)\", \"reciever_id\": \"61\", \"\(username)\": \"2017-05-09 03:02:55 pm\"}"
i cant able pass dic in api. problem is, have 1 array how can convert array string . have add 1 more parameter in dic , pass array here code how generating array
( { desc = "this suger m23 type "; price = 50; product = "suger temp"; }, { desc = "this suger m23 type "; price = 50; product = "suger temp"; } )
code
let ary_allproduct :nsmutablearray = [] in 0..<count { var dict = dictionary<string, any>() dict["product"]="suger temp" dict["desc"]="this suger m23 type " dict["price"]="50" ary_allproduct.add(dict) } print(ary_allproduct)
in swift, please apply code.
let jsondata = try? jsonserialization.data(withjsonobject: dictionary, options: jsonserialization.writingoptions()) let jsonstring = nsstring(data: jsondata!, encoding: string.encoding.utf8.rawvalue) print(jsonstring)
note: on console it'll print string. if check on breakpoint. you'll see exact format needed , should work.
on console: ({"nacho":["1","2","3"]})
Comments
Post a Comment