[英]Streaming JSON with AFNetworking on IOS
What would be the most elegant way to receive data from a streaming JSON API using AFNetworking? 使用AFNetworking从流式JSON API接收数据的最优雅方式是什么? AFNetworking provides excellent support for receiving non-streaming data from JSON APIs, but I couldn't find any examples of streaming JSON.
AFNetworking为从JSON API接收非流数据提供了出色的支持,但我找不到任何流JSON的例子。
AFNetworking does not have a built-in streaming SAX-style JSON operation, but it should be straight forward to create your own. AFNetworking没有内置的流式SAX风格的JSON操作,但它应该是直接创建自己的。
AFJSONRequestOperation
AFJSONRequestOperation
的子类 outputStream
property of the operation during initialization to hook it up to a JSON parser that supports SAX-style parsing (such as Yajl ). outputStream
属性将其连接到支持SAX样式解析的JSON解析器(例如Yajl )。 The parser will read data and build up the JSON object as it comes in responseJSON
property to read the cached object from the parser responseJSON
属性以从解析器中读取缓存的对象 setReceivedJSONBlock:((^)(void (id JSON))block
). This block will probably be triggered by delegate methods sent from the parser (eg <YAJLParserDelegate> -parserDidEndDictionary:
). setReceivedJSONBlock:((^)(void (id JSON))block
)这个块可能是由解析器发送的委托方法触发的(例如<YAJLParserDelegate> -parserDidEndDictionary:
。 If you are able to get this working, I would encourage you to publish and share this with others. 如果你能够使这个工作,我鼓励你发布并与他人分享。 I think this could be useful to quite a few people.
我认为这可能对很多人有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.