Streaming JSON with AFNetworking on IOS
What would be the most elegant way to receive data from a streaming JSON API using AFNetworking? AFNetworking provides excellent support for receiving non-streaming data from JSON APIs, but I couldn’t find any examples of streaming JSON.
Solutions Collect From Internet About “Streaming JSON with AFNetworking on IOS”
AFNetworking does not have a built-in streaming SAX-style JSON operation, but it should be straight forward to create your own.
- Create a subclass of
- Use the
outputStreamproperty of the operation during initialization to hook it up to a JSON parser that supports SAX-style parsing (such as Yajl). The parser will read data and build up the JSON object as it comes in
- Hook up the
responseJSONproperty to read the cached object from the parser
- …or depending on how you’re doing streaming, you may need to add a new property that defines a block to execute when new JSON objects come back (e.g.
setReceivedJSONBlock:((^)(void (id JSON))block). This block will probably be triggered by delegate methods sent from the parser (e.g.
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.
- iPhone – Adjust UILabel width according to the text
- Will Xcode 4.3.2 suffice to build apps for iOS 6?
- Native Facebook Login stopped working after SDK update to 3.14
- iOS/UI Automation: UIAActionSheet does not have possibilities to manipulate with buttons
- Search result icons in Xcode?
- Adding constraints programmatically in UIScrollView with dynamic buttons – Swift
- Drawing a sketchy-looking line, programmatically
- Does Google Mobile Vision support OCR on iOS?
- Urban Airship – send PUSH to 1 specific device (device token)
- Firebase Upgrading From 2.5.1 to 3.2.1
- How do I register NSUndoManager in Swift?
- Duplicate symbol _OBJC_CLASS_$_Facebook
- iOS – Drag and drop collision detection How to detect when your selected item drags over another subview?
- ASIHTTPRequest fails in production builds
- Read and write data from text file