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

Capture and play voice with Asterisk ARI -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -