简体   繁体   English

使用Swift 3将大型JSON保存到Realm

[英]Save a large JSON to Realm using Swift 3

I have a JSON with more or less 75 keys. 我有一个包含约75个键的JSON。

I need to receive this JSON and store offline it using Realm. 我需要接收此JSON并使用Realm将其离线存储。

I do not want to iterate through the keys, since I've heard that there are ways to save a large JSON using a few lines. 我不想遍历键,因为我听说有一些方法可以使用几行来保存大型JSON。 How can I do this? 我怎样才能做到这一点?

EDIT: My JSON ( I saved on a server away because it's too big) http://myjson.com/i7e6l 编辑:我的JSON(我保存在服务器上,因为它太大了) http://myjson.com/i7e6l

There is no easy, one liner to parse the JSON and store it in Realm , since each JSON response is unique and no framework can have explicit knowledge about the structure of your JSON response without you giving some information to this framework about your JSON . 有没有简单的,一个衬垫解析JSON并将其存储在Realm ,因为每个JSON的反应是独一无二的,没有一个框架能对您的结构显性知识JSON没有你提供了一些信息,有关这个框架响应JSON

You will need to write some code either to parse the response or to make a mapping between your JSON response's fields and the properties of your Realm object. 您将需要编写一些代码来解析响应或在JSON响应的字段与Realm对象的属性之间进行映射。 If you choose the latter solution, you can use Alamofire Object Mapper to do the JSON parsing automatically, but even then you have to write code for the mapping. 如果选择后一种解决方案,则可以使用Alamofire对象映射器自动进行JSON解析,但是即使如此,您也必须编写映射代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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