[英]Is it possible to serialise a Realm Object into JSON?
有谁知道Realm(iOS)中是否支持将RLMObject
序列化为JSON以进行导出?
I don't believe there is any support officially, but this article may describe some other third party libraries which may be able to achieve what you are after 我不认为官方会提供任何支持,但是本文可能会介绍一些其他第三方库,这些第三方库可能能够实现您所追求的目标
http://blog.matthewcheok.com/working-with-realm/ http://blog.matthewcheok.com/working-with-realm/
It should work like with any other objects: 它应该与其他任何对象一样工作:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:realmObject options:NSJSONWritingPrettyPrinted error:&writeError];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
But: 但:
An object that may be converted to JSON must have the following properties:
可能转换为JSON的对象必须具有以下属性:
The top level object is an NSArray or NSDictionary.
顶级对象是NSArray或NSDictionary。
All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
所有对象都是NSString,NSNumber,NSArray,NSDictionary或NSNull的实例。
All dictionary keys are instances of NSString.
所有字典键都是NSString的实例。
Numbers are not NaN or infinity.
数字不是NaN或无穷大。
https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/index.html] https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/index.html]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.