【问题标题】:Is it possible to serialise a Realm Object into JSON?是否可以将领域对象序列化为 JSON?
【发布时间】:2015-04-29 10:12:00
【问题描述】:

有谁知道 Realm (iOS) 中是否支持将RLMObject 序列化为 JSON 以进行导出?

【问题讨论】:

标签: ios json swift realm


【解决方案1】:

我不相信官方有任何支持,但是本文可能会描述一些其他第三方库,它们可能能够实现您所追求的目标

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

【讨论】:

    【解决方案2】:

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

    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]

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2020-05-24
      相关资源
      最近更新 更多