ios - Converting NSDictionary to JSON in Objective C -


this question has answer here:

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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -