Stream based JSON parsing on Swift
Asked Answered
S

1

15

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

Suppose answered 24/8, 2016 at 12:4 Comment(3)
Wow, no action on this in over a year and a half.Methylamine
JSON parsing is not hard at all. Why not write your own parser?Thor
Maybe is better approach if you send the json from the server in parts. I mean, X number of elements each timeFarant
K
11

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)

Kaunas answered 21/4, 2018 at 7:43 Comment(1)
Yeah, this is again an Obj-C based approach. I was looking for something Swift based actually.Suppose

© 2022 - 2024 — McMap. All rights reserved.