是否可以将 Realm 对象序列化为 JSON?
Is it possible to serialise a Realm Object into JSON?
有谁知道 Realm (iOS) 是否支持将 RLMObject
序列化为 JSON 以供导出?
我不相信有任何官方支持,但这篇文章可能会描述一些其他第三方库,这些库可能能够实现您所追求的
它应该像任何其他对象一样工作:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:realmObject options:NSJSONWritingPrettyPrinted error:&writeError];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
但是:
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.
有谁知道 Realm (iOS) 是否支持将 RLMObject
序列化为 JSON 以供导出?
我不相信有任何官方支持,但这篇文章可能会描述一些其他第三方库,这些库可能能够实现您所追求的
它应该像任何其他对象一样工作:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:realmObject options:NSJSONWritingPrettyPrinted error:&writeError];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
但是:
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.