简体   繁体   English

用于解析JSON的iOS设计模式

[英]iOS design pattern for parsing JSON

I'm making a simple app that parses some cached instagram json. 我正在制作一个简单的应用程序,用于解析一些缓存的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. 我只有两个视图:1.带有图像缩略图的uiCollectionView视图; 2.模态视图,一旦用户点击缩略图,模态视图就会显示更大的图像以及一些其他instagram信息(用户,位置等)。

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. 有很多教程讲解集合视图和解析json,但是我很难找到如何将它们组合在一起的方法。 I was thinking having classes for: the collection view, the modal view, and one for parsing the json. 我正在考虑为以下类提供类:集合视图,模式视图以及用于解析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)? 我是否应该添加一个类来跟踪instagram数据的每个实例(包含图像和用户数据的容器)? Should I use a singleton to have access the instagram data across every class? 我应该使用单例在每个班级访问instagram数据吗?

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. 现在,对于解析JSON,我想所有很酷的孩子都在使用javascript核心来进行解析。

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

You can then pull the result out as a dictionary or array. 然后,您可以将结果作为字典或数组拉出。

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

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