ios - Converting NSDictionary to JSON in Objective C -
this question has answer here:
- generate json string nsdictionary in ios 12 answers
i want generate json in objective c , below example, 1 dictionary has fields, , within dictionary want add dictionary. i.e. student dictionary can have subjects dictionary(which can have multiple items.
{ "student": { "name": "b", "std": "d", "subjects": [{"id":"1","id":"2","id":"3"}] }}
i trying using nsjsonserialization , tried first creating json string of subjects dictionary but, after converting final json of main dictionary showing (slash) breaking json. added subjects inside main dictionary after converting showing subjects json starting (
any suggestion m missing?
thanks
use nsjsonserialization :
nsdata *jsondata = [nsjsonserialization datawithjsonobject:dictionaryorarraytooutput options:nsjsonwritingprettyprinted error:&error];
reference : https://stackoverflow.com/a/9020923/3222713
and "slash" problem : https://stackoverflow.com/a/19651309/3222713
Comments
Post a Comment