ios中怎样用json
答案:2 悬赏:0 手机版
解决时间 2021-02-26 06:05
- 提问者网友:温柔港
- 2021-02-25 19:06
ios中怎样用json
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-02-25 20:20
可以使用NSDictionary中的键值对来拼接Json数据,非常方便,也可以进行嵌套,直接上代码:
//开始拼接Json字符串
NSDictionary *dataDictionary= [NSDictionary dictionaryWithObjectsAndKeys:@"mac",@"mac",
@"game",@"game",
@"devicetoken",@"devicetoken",
@"device",@"device",
@"gv",@"gv",
@"lang",@"lang",
@"os",@"os",nil];
NSDictionary *parmDictionary= [NSDictionary dictionaryWithObjectsAndKeys:@"getSession",@"act",
dataDictionary,@"data",nil];
NSDictionary *jsonDictionary=[NSDictionary dictionaryWithObjectsAndKeys:@"pv",@"pv",
parmDictionary,@"param",nil];
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *jasonString = [writer stringWithObject:jsonDictionary];
NSLog(@"%@",jasonString);
//开始拼接Json字符串
NSDictionary *dataDictionary= [NSDictionary dictionaryWithObjectsAndKeys:@"mac",@"mac",
@"game",@"game",
@"devicetoken",@"devicetoken",
@"device",@"device",
@"gv",@"gv",
@"lang",@"lang",
@"os",@"os",nil];
NSDictionary *parmDictionary= [NSDictionary dictionaryWithObjectsAndKeys:@"getSession",@"act",
dataDictionary,@"data",nil];
NSDictionary *jsonDictionary=[NSDictionary dictionaryWithObjectsAndKeys:@"pv",@"pv",
parmDictionary,@"param",nil];
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *jasonString = [writer stringWithObject:jsonDictionary];
NSLog(@"%@",jasonString);
全部回答
- 1楼网友:逃夭
- 2021-02-25 21:10
可以的,但是你要将json转换成你的数据结构,xml也一样,不可能直接去load一个json或者xml数据
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯