nsdictionary - nsstring
+ (nsstring*) Stringinjsonformatforobject: (ID) obj{NSData*jsondata =[nsjsonserialization datawithjsonobject:obj options:0 //If that option isn't set, the most compact possible JSON would be generatedError:nil]; NSString*jsonstring =[[NSString alloc] Initwithdata:jsondata encoding:nsutf8stringencoding]; Jsonstring= [jsonstring stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]];//remove the white and trailing whitespace characters and newline characters returnjsonstring;}
nsstring - nsdictionary
+ (Nsdictionary *) dictforjsonstring: (NSString *) str{ *jsondata = [str datausingencoding: Nsutf8stringencoding]; *err; *dic = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingmutablecontainers Error: Nil]; return DiC;}
IOS nsdictionary <--> nsstring (JSON) in OBJC