I would be open to that. Ideally, we would just update the parser to
handle the different cases, but this could be a quick way to do it
until or unless someone voluteers to look at the current implimentation.
mike chambers
mike chambers
> <JSON.as>
It is failing on:
--
o = JSON.decode( ' "http:\/\/digg.com\/security\/Simple_Digg_Hack" ' );
assertTrue( "String not decoded correctly", o =="http://digg.com/security/Simple_Digg_Hack
" );
--
mike chambers
The only issue with having a separate normalize or cleanup method
call, is that then we would have to document when it would not work...
i.e. in the case of the url below.
Unfortunately, I am not very strong with RegularExpressions.
So, the primary issue is that currently the parser only works if the
property name in an object is quoted?
i.e:
Works:
{"foo":"bar"}
doesnt work:
{foo:"bar"}
let me ping Darron (Who wrote the original code) and see if he has any
ideas.
Maybe we can have a strict property which defaults to true (current
behaviour). If set to false, then it was parse non-quoted values.
mike chambers
I dont have time to work on this right now, so if someone else wants
to try it out, go for it. Otherwise I will look at it when I get a
chance:
---
Mike Chambers
hey darron, you have a sec for a quick question?
2:06
haystackr
sure
whats up?
2:06
Mike Chambers
you remember the JSON code you wrote for us?
for corelib?
2:06
haystackr
yeah
well, I dont really "remember" it, but I wrote it 2 years ago.. hehe
2:06
Mike Chambers
the spec specifies the object values are enclosed in doubel qwuotes
{"foo":"bar"}
which the lib works with
but apparently a lot of json doesnt do this
{foo:"bar"}
2:07
haystackr
teh web iz borken
2:07
Mike Chambers
amen to that
so I am looking into adding a strict flag
2:07
haystackr
yeah, we can update the parser to not look for a " after a {
right now it looks for a string value after {
2:08
Mike Chambers
yeah
2:08
haystackr
would have to make some code to recognize identifiers
2:08
Mike Chambers
is that something relatively easy?
2:08
haystackr
and ask for an ident or string after {
relatively, yeah
2:08
Mike Chambers
im looking through it now, but not familiar with the code
2:08
haystackr
i dont have it in front of me, so can't really point you to it
its probably in tokenizer
you need a new ident token
so when you call getNextToken() you can get a string or an ident
in the parseObject() portion
2:09
Mike Chambers
yeah. im looking at parseObject
2:09
haystackr
its like getNetxToken() for open_curly_brace
then look for ident or string
you'll have to write that part
not sure if that's quite right as I dont rmemeber 100%
2:10
Mike Chambers
http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/serialization/json/JSONDecoder.as
2:10
haystackr
but that's the general idea
2:10
Mike Chambers
if you have a sec, can you leave the comments inline on that page?
just click on the code line and you can leave a comment
2:11
haystackr
you have to edit this one too: http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/serialization/json/JSONTokenizer.as
2:11
Mike Chambers
getNextToken?
2:11
haystackr
in getNextToken()
new case for idents
gonna have to figure out a way to work around the case "t", "f" and "n"
2:11
Mike Chambers
yeah
2:11
haystackr
as thoughs could start tokens as well as true/false, etc
its more like.. just grab the ident in that case
then check if the dent is the special case true/false/null
otherwise toekn.type = IDENT
2:12
Mike Chambers
ok. you have lost me, but i am not as familiar with the code
2:12
haystackr
for JOSNDecoder
like 182 -- else if token.type == JSONTokenType.IDENT
or, line 151 can be token.type == string or token.type == ident
the only thing that would change would be line 153
actually, 153 wouldn't have to change at all
because the value of the tokne would be astring
eah, you just need to say if string or ident there on 151
2:14
Mike Chambers
thats it?
2:14
haystackr
then make tokenize recognize ident tokens
yeah
2:14
Mike Chambers
what is ident?
2:14
haystackr
a new JSONTokenType
that represents an identifiers
(so the parse knows what the next token type is..)
2:15
Mike Chambers
right
and then in JSONTokenizer is where i set the IDENT type
the JSONTokenType
2:16
haystackr
yeah
when you find an identifer in getNextToken()
you set token.type = IDENT
2:16
Mike Chambers
would that just be in default then?
if it is not a number
2:16
haystackr
possibly
2:17
Mike Chambers
i assume it is a name
2:17
haystackr
if it's not a number, just consume valid ident chars (A-Z, a-z, $_)
but
that won't work, remember, because of the "t", "f", and "n" cases
you need to get rid of those
and check after you're done with the ident parsing code
2:18
Mike Chambers
before i return the token?
2:18
haystackr
yeah
2:18
Mike Chambers
so if the token was "false"
2:18
haystackr
get your ident, then check its value.. if "false" token type is FALSE
2:18
Mike Chambers
i would
token.value = false;
2:19
haystackr
exactly
2:19
Mike Chambers
that is outside of the swtich statement?
right?
2:19
haystackr
otherwie, token.type = IDENT
2:19
Mike Chambers
just remove those cases
2:19
haystackr
that would be in the default case handler
2:19
Mike Chambers
oh
in the default
but remove the f,t cases
2:19
haystackr
right
I would actually make a new method
and put the t, f, and n in there
new methods called readIdentifier()
then in default you case say, on line 165, else if ( isIdentChar( ch )
token = readIdentifier()
that should do it
good luck
readIdentifier will be a lot like readString()
minus the question sequence stuff
gotta run
let me know how it works out
-
mike chambers
me...@adobe.com
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "ActionScript 3 Core Library" group.
> To post to this group, send email to as3co...@googlegroups.com
> To unsubscribe from this group, send email to as3corelib+...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/as3corelib?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
XML does have the ignoreWhiteSpace static property though, which
applies to all instances.
I prefer #1, but I could go either way. I wouldn't do both though as
that could be confusing (which takes precedence, etc..).
Ill defer to whatever you think makes the most sense.
mike chambers