Open darronschall opened 14 years ago
Updated by darron.schall on 2009-07-08T19:08:33
Hi Marko,
This is definitely something to consider. Other people have requested this type of functionality. See this question on stack overflow: http://stackoverflow.com/questions/869780/streaming-parsers-json-xml-for- as3-flex-adobe-air-application
I'm not sure of the best approach right now, but I'll take a look at this patch as well as the answer to the question on stack overflow and see if this warrants building support directly into the API, or if it just needs an example added on the wiki about how to use this library when trying to read potentially incomplete data.
Added label Type-Patch
Updated by marko.kocic on 2009-07-09T10:28:56
Hi,
I'm attaching the slightly improved version of the patch that was used in my application. I know it is not ideal, since my goal was to modify as little as possible upstream code.
I think that some support for streaming will be useful, especialy since it can be localized to separate class without affecting existing code.
Originally filed by marko.kocic on 2009-02-12T16:03:24
It would be a great addition to json library if it could be used to decode String stream. It is usefull when you are reading a sockes and parsing its content on the fly.
I slightly modified JSONDecoder and JSONTokenizer (made some vars public) and addet new classes JSonFlow and JSonDataEvent. JSonFlow can take partial json strings in its feedIt method. Then it parses the string and generates events whenever it parses some object.
It basically works, but I still didn't figure out the best way to handle errors. Currently, if ParseError is catched, it just aborts and waits for new feed of data, assuming it failed because of incomplete input. Real error handling would probably raquire more changer to Tokenizer.
Are you interesting in cleaning this up and adding to the one of the following releases?
Regards, Marko Kocić
Attached 2 files.