是否有可能将Realm对象串行化为JSON?

有谁知道是否有任何Realm(iOS)的支持能够将一个RLMObject序列化成JSON导出?

我不相信有任何正式的支持,但这篇文章可能会描述一些其他的第三方库可能能够实现你所

http://blog.matthewcheok.com/working-with-realm/

它应该像任何其他对象一样工作:

 NSData *jsonData = [NSJSONSerialization dataWithJSONObject:realmObject options:NSJSONWritingPrettyPrinted error:&writeError]; NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 

但:

可以转换为JSON的对象必须具有以下属性:

顶级对象是NSArray或NSDictionary。

  • 所有对象都是NSString,NSNumber,NSArray,NSDictionary或NSNull的实例。

  • 所有的字典键都是NSString的实例。

  • 数字不是NaN或无穷大。

https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/index.html%5D