Page 1 of 1
libJson
Posted: Wed Jan 07, 2009 5:23 pm
by Mark Smith
Here's a first go at a json parser/generator that converts between revolution arrays and json objects/arrays, to an arbitrary level of nesting. It has some basic formatting capability also.
As usual, any observations, modifications, disasters or other comments welcome.
http://futsoft.futilism.com/revolutionstuff.html
Best,
Mark
problem with download link
Posted: Mon Mar 09, 2009 9:54 pm
by nimbleRev
hey Mark,
When I click the download link on your site I get an xml error message, from S3 that says "Access Denied". Is there another URL I can try?
I'm Really excited to check out your json library!
Posted: Tue Mar 10, 2009 3:33 am
by Mark Smith
Sorry about that! I just noticed from the logs that people were getting "access denied" - I had the permissions set wrong. It's fixed now, so you should be able to dl it.
Best,
Mark
Posted: Tue Mar 10, 2009 6:42 pm
by nimbleRev
Thanks for updating the link! Downloaded and got it working. Ah, sweet JSON bliss in RunRev
I'm new to the Rev world and was curious to find out the best practice for including a library like this in my stack?
From what I've read so far it seems like there are many options from including it as an external within the Stack inspector to manually adding it to the back scripts when the Stack opens, or maybe a combination of both?
Posted: Wed Mar 11, 2009 2:34 am
by Mark Smith
It all depends - the simplest approach is simply to include it as a substack of your main stack, and then 'start using' it on startup.
You can also 'start using' or 'insert into back' when required, and 'stop using' or 'remove from back' when no longer needed.
To be honest, I'm not very sure what the difference really is between 'start using' and 'insert into back'. I haven't seen any noticeable differences in my own projects, so I guess whatever seems most convenient in terms of your application design...
Do let me know if you run into any problems with libJson.
Best,
Mark
Posted: Thu Mar 12, 2009 2:47 am
by nimbleRev
I appreciate the tips Mark. I think I'm going to use "insert into back" for now. From what I understand when I use "insert into" for libjson it will only take the stack script and insert it into my stack's back scripts, which is perfect. But the "start using" command seems like it will load everything in the stack which would include your sample card and all the scripts in your buttons. I'm not 100% sure on that but seems like insert is better for including a library.
Thanks again for sharing the JSON library with the community. It's working great

I'll let you know if anything comes up.
Posted: Thu Mar 12, 2009 11:17 pm
by Mark Smith
Great!
Mark
Fix proposal to deal with diacritics characters
Posted: Wed Sep 09, 2009 11:37 am
by imed-edition
Mark,
Diacritics does not seem to convert appropriately. I suggest to change the two following handlers to:
Code: Select all
private function unicodeEscapes pString
put false into inEsc
repeat for each char c in pString
add 1 to count
put c after buffer
if count < 2 then next repeat
if buffer is "\u" then put true into inEscape
if inEscape then
if length(buffer) < 6 then
next repeat
else
-- TO DEAL WITH DIACRITICS :
if platform() is "MacOS" then
put isotomac(numtochar(baseconvert(char 3 to 6 of buffer, 16, 10))) into buffer
else
put numtochar(baseconvert(char 3 to 6 of buffer, 16, 10)) into buffer
end if
put false into inEscape
end if
else
put char 1 of buffer after nString
delete char 1 of buffer
end if
end repeat
put buffer after nString
return nString
end unicodeEscapes
private function json.encodeString pString
set the casesensitive to true
repeat with i=0 to 7
replace numtochar(i) with "\u" & format("%04x", i) in pString
end repeat
replace numtochar(8) with "\b" in pString
replace numtochar(9) with "\t" in pString
replace numtochar(10) with "\n" in pString
replace numtochar(11) with "\u" & format("%04x", i) in pString
replace numtochar(12) with "\f" in pString
replace numtochar(13) with "\r" in pString
repeat with i=14 to 31
replace numtochar(i) with "\u" & format("%04x", i) in pString
end repeat
replace "\" with "\\" in pString
replace quote with "\u0022" in pString
-- TO DEAL WITH DIACRITICS :
if platform() is "MacOS" then
repeat with i=129 to 255
put numtochar(i) into c
put format("%04x",chartonum(mactoiso(c))) into tHexEncode
replace c with "\u" & tHexEncode in pString
end repeat
else
repeat with i=129 to 255
replace numtochar(i) with "\u" & format("%04x", i) in pString
end repeat
end if
if sUnicodeInput then
return pString
else
return utf8encode(pString)
end if
end json.encodeString
I'll be glad if someone can do a second check on the results. Especially, I do not have ready access to check under Windows.
Thanks! Hope this helps...
iMed Editor
two bugs ?
Posted: Wed Sep 09, 2009 1:21 pm
by imed-edition
In the two following functions :
Code: Select all
private function jObjectToArray
private function jArrayToArray
It appears that the first of the three following lines should be changed from:
Code: Select all
repeat while sIndex <= sNumTokens
add 1 to sIndex
switch sJson[sIndex]
to:
Code: Select all
repeat while sIndex < sNumTokens -- and not: <=
otherwise, the
sIndex in
will go out of
sNumTokens which is the max index bound value.
If someone is interested I can drop a new version of the stack including the fix from our previous post.
iMed Editor
(look at
http://www.imed-edition.net/rev/index.html to display our direct email)
Posted: Wed Sep 09, 2009 8:52 pm
by Mark Smith
Thanks or these - I'll get the lib updated tonight!
Best,
Mark
Posted: Wed Sep 09, 2009 9:04 pm
by Mark Smith