Re: [Pyparsing] jsonParser.py patch
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2008-04-22 21:13:57
|
Thomas - Hrm, well, I can see that this works, but I'm not sold. A jsonObject really *isn't* a choice between a jsonDict and a jsonArray. It really is a '{' members '}', as per the BNF. I think the real problem is elsewhere. The RFC link you gave was very helpful. It states that the content of the JSON string can be any JSON value, which you tripped over because you encountered a JSON array when we were parsing for a JSON object. The solution is not to change the definition of jsonObject. The solution is that we should have been invoking this: jsonValue.parseString(testdata) not this: jsonObject.parseString(testdata) which was my mistake in the original code. Not thinking, I assumed that JSON object was the all-encompassing type, but JSON value is what we are really being given. jsonValue already encompasses checking for all the different JSON value types - not just object and array, but also number, true, false, etc. Try reverting to the original jsonParser.py, but change this statement instead and see if you get successful parsing. (You may find that the results are nested an extra level deep, you'll have to pick out element [0] of the data returned from parseString.) I'll fix this in the next release (coming soon, I hope)! Cheers, -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of thomas_h Sent: Tuesday, April 22, 2008 2:43 PM To: pyp...@li... Subject: Re: [Pyparsing] jsonParser.py patch Done. It's at http://pyparsing.pastebin.com/m2c33d08d, if that is of help. Thanks for the hints. Thomas On Tue, Apr 22, 2008 at 6:40 PM, Paul McGuire <pt...@au...> wrote: > Your attachment was stripped somewhere along the way. Could you > please paste it to a http://pyparsing.pastebin.com/? > > Thanks, > -- Paul > > > > -----Original Message----- > From: pyp...@li... > [mailto:pyp...@li...] On Behalf Of > thomas_h > Sent: Tuesday, April 22, 2008 10:35 AM > To: pyp...@li... > Subject: [Pyparsing] jsonParser.py patch > > Hi all, > > I've changed the jsonParser.py example from the distro to accommodate > top-level arrays (as of RFC4627, http://tools.ietf.org/html/rfc4627). > Please find the patch attached. > > Cheers, > Thomas > > ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javao ne _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |