如何将NSDictionary转换为JSON对象?

spe*_*tak 3 iphone json objective-c nsdictionary ios

我还在学习JSON,并使用SBJSON.我将如何获取NSDictionary并将其转换为类似于此的JSON对象:

{"id":"123","list":"456","done":1,"done_date":1305016383}
Run Code Online (Sandbox Code Playgroud)

小智 6

使用SBJSON添加到NSDictionary的类别:

NSString *jsonString = [dictionary JSONRepresentation];
Run Code Online (Sandbox Code Playgroud)

只需在字典中正确命名键和值,SBJSON就能为您完成工作