lukmanid / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

Allow json to decode streamed data / async json parser #93

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by marko.ko...@gmail.com on 12 Feb 2009 at 4:03

Attachments:

GoogleCodeExporter commented 8 years ago
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.

Original comment by darron.schall on 8 Jul 2009 at 7:08

GoogleCodeExporter commented 8 years ago
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.

Original comment by marko.ko...@gmail.com on 9 Jul 2009 at 10:28

Attachments: