将NSDictionary转换为JSON

将NSDictionary转换为JSON

问题描述:

如何将NSDictionary转换为JSON?

我已使用json将字典发布到服务器中。并且在使用GET方法从服务器接收数据的时间。使用普通的密钥调用方法无法访问数据,例如

I have posted a dictionary into server using json. And in the time receiving the data from the server using GET method. the data cant be accessed using normal key calling method like

_secretanswer.text=[[NSString alloc]initWithFormat:@"%@",[customfield objectForKey:@"secanswer"]];  

服务器返回NCFString作为结果。

the server returning a NCFString as the result.

如何以JSON格式转换和发布NSDictionary?

How to convert and post a NSDictionary in the JSON format?

NSError * error;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:myDictionary options:0 error:&error]; 

NSString * myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]