将NSDictionary转换为JSON [英] Convert NSDictionary To JSON

查看:498
本文介绍了将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]    

这篇关于将NSDictionary转换为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆