尝试设置值/密钥对时出现以下错误:
2011-06-21 16:21:16.727 agent[94408:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SBJsonWriter 0xab31230> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key key.'代码如下:
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
[writer setValue:@"val" forKey:@"key"];
NSString *json = [writer JSONRepresentation];
NSLog([NSString stringWithFormat:@"json: @%", json]); 发布于 2011-06-22 04:32:28
即使用来自(NSObject)类别的键值编码,
要使用字典接口:导入JSON.h,然后:
NSMutableDictionary * dict = [NSMutableDictionary new];
[dict setValue:@"val" forKey:@"key"];
NSLog(@"json: %@", [dict JSONRepresentation]);附注:NSLog接受一种格式,因此您不需要从一种格式生成一个字符串来传递给它。
https://stackoverflow.com/questions/6431552
复制相似问题