-->

iPhone, Core Data and JSON

2020-07-23 08:53发布

问题:

I have a web site with an API which publishes the information using JSON. I can access this API fine, but I would really like to store the information in an iPhone application using Core Data. Is there a way to hook the Persistent Store to the JSON API so rather than having to keep them in sync using some algorithm I can just use the web site as the back end for Core Data.

I hope that is clear.

回答1:

If you just want to use Core Data for its object graph management facilities, you can parse the JSON data and create an object graph associated with an in memory store.

If you want to persist this data in a serialized JSON format, Core Data does have the facility for creating new atomic store types. You could write a JSON store as an alternative to the XML store format.



回答2:

No, you can only use XML, SQLite, or an in-memory store.



回答3:

There is a lib that does JSON => Core Data synchronization : https://github.com/sixdegrees/lidenbrock