简体   繁体   中英

iOS design pattern for parsing JSON

I'm making a simple app that parses some cached instagram json. I only having two views 1. an uiCollectionView view with thumbnails of the images and 2. a modal view that shows a larger image along with some other instagram info (user, location, etc) once the user taps the thumbnail.

There are a lot of tutorials explaining collection views and parsing json, but I am having a hard time finding how to put it all together. I was thinking having classes for: the collection view, the modal view, and one for parsing the json.

Is that best practice? Should I add a class that keeps track of each instance of the instagram data (container holding the image and user data)? Should I use a singleton to have access the instagram data across every class?

Any design advice or links are appreciated! Happy Holidays

For parsing JSON now I would guess all the cool kids are using javascript core to do the parsing.

JSContext *context = [[JSContext alloc] init];
JSValue *result = [context evaluateScript: @"{ someJSON: 'string' }"];

You can then pull the result out as a dictionary or array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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