JSONKit:更改和序列化JSON属性的值 [英] JSONKit: changing and serializing JSON attribute's value

查看:206
本文介绍了JSONKit:更改和序列化JSON属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSONKit将JSON字符串解析为NSDictionary:

I am using JSONKit to parse JSON string into NSDictionary:

NSDictionary *deserializedData = [jsonString objectFromJSONString];

我的问题是:如何更改字典值并获取更改的JSON字符串?

My question is: how can I change the dictionary values and get a changed JSON String?

我试图更改字典值:

[deserializedData setObject:[NSNumber numberWithInt:iRatings] forKey:@"ratings"];   

但是应用程序在该行崩溃.我在做什么错了?

But the app crashes in that line. What am I doing wrong?

提前谢谢!

推荐答案

虽然其他答案正确,但在这种情况下,您真正​​想要的是:

While the other answers are correct, what you really want in this case is:

NSMutableDictionary *deserializedData = [jsonString mutableObjectFromJSONString];

mutableObjectFromJSONString方法将直接创建一个可变字典,从而节省时间和内存.

The mutableObjectFromJSONString method will create a mutable dictionary directly, which saves time and memory.

这篇关于JSONKit:更改和序列化JSON属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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