当我将 Dictionary 与对象数组一起使用时,出现以下错误:
NSMutableDictionary *jsonDict=[[NSMutableDictionary alloc] init];
[jsonDict setObject:checkMarkPresetRecipientsArray forKey:@"Names"];
[jsonDict setObject:checkMarkDocumentGroupNameArray forKey:@"Address"];
json = [jsonDict JSONFragment];
错误:JSONFragment 失败。错误跟踪是:( "Error Domain=org.brautaset.JSON.ErrorDomain Code=1 \"DocumentType 不支持 JSON 序列化\" UserInfo=0xb5cc270 {NSLocalizedDescription=DocumentType 不支持 JSON 序列化}", "Error Domain=org. brautaset.JSON.ErrorDomain Code=1 \"Unsupported value for key DocumentTypes in object\" UserInfo=0xb580e60 {NSUnderlyingError=0xb585320 \"JSON serialization not supported for DocumentType\", NSLocalizedDescription=Unsupported value for key DocumentTypes in object}" )
但没有得到相同的错误:
NSMutableDictionary *jsonDict=[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Nitesh",@"Name", @"Balaghat",@"Address",nil];
NSString *json=[jsonDict JSONRepresentation];
NSLog(@"%@",json);
上面给了我正确的 JSON 表示。
我做错了什么?任何人都可以在上面帮助我....
实际上我的数组包含核心数据类对象,它不支持 JSON 表示,所以我通过实现进行了更改,现在它工作正常。如果有任何方法可以更改 JSON 中的 coredata 类对象表示,请更新我。谢谢。