我在我的iPhone应用程序中使用JSONKit解析从服务器返回的JSON字符串。服务器响应的一部分是一些Base64编码的图像,我想将其解码为实际图像并添加到解析器创建的对象中。问题是我似乎无法弄清楚解析器返回的是什么类,因此可以使用什么方法与该对象交互。我已经搜索了JSONKit文档寻找答案,但没有找到。
decodedData = [[request responseString] objectFromJSONString];
int i = 0;
[Base64 initialize];
for (NSString *base64String in [decodedData valueForKey:@"base64String"]) {
UIImage *image = [UIImage imageWithData:[Base64 decode:base64String]];
[decodedData setValue:image forKey:@"image"];
i++;
}
这段代码放在一个方法里,在请求成功完成并且响应以JSON格式返回的时候被调用,响应字符串保存在[request responseString]
中。 decodedData
对象的类在头文件中定义。无论我将其声明为NSArray
、NSMutableArray
、NSDictionary
或NSMutableDictionary
,当运行代码时都会得到相同的错误(编译很顺利)。错误信息如下:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[JKDictionary setObject:forKey:]: mutating method sent to immutable object'
请问这个对象是什么类型的类,我应该如何将Base64解码后的图片添加到对象中?
我对Objective-C还很陌生,请多多包涵。谢谢。