How to parse JSON being downloaded as a stream on Swift? The stream gives incomplete JSON data each time. This is because I have to download MBs of data, the main component of which is a long array of objects, and I do not want the user to wait till I get the complete data. Is it possible to keep parsing the JSON data sequentially while streaming? Basically, something like what Jackson allows on Android, or a YAJLiOS Parser implementation for Swift
JSON streaming comprises communications protocols to delimit JSON objects built upon lower-level stream-oriented protocols (such as TCP), that ensures individual JSON objects are recognized, when the server and clients use the same one (e.g. implicitly coded in).
Swift JSON ParsingJSON stands for JavaScript Object Notation. It's a popular text-based data format used everywhere for representing structured data. Almost every programming language supports it with Swift being no exception. You are going to use JSON a lot throughout your career, so make sure you don't miss out.
An object that converts between JSON and the equivalent Foundation objects.
Basically, what you require is a SAX parser. NSJSONSerialization is a DOM parser. One such implementation for sax parsing is here
https://github.com/dhoerl/SAX-JSON-Parser-ForStreamingData
where the data is parsed as and when the data is received. For more info check this answer iPad - Parsing an extremely huge json - File (between 50 and 100 mb)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With