简体   繁体   中英

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/

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:

The top level object is an NSArray or NSDictionary.

  • All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.

  • All dictionary keys are instances of NSString.

  • Numbers are not NaN or infinity.

https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/index.html]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM