簡體   English   中英

是否可以將Realm對象序列化為JSON?

[英]Is it possible to serialise a Realm Object into 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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM