libJson
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
libJson
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
As usual, any observations, modifications, disasters or other comments welcome.
http://futsoft.futilism.com/revolutionstuff.html
Best,
Mark
problem with download link
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!
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!
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
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?

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?
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
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
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
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.
Thanks again for sharing the JSON library with the community. It's working great

-
- Posts: 12
- Joined: Fri Apr 21, 2006 1:53 pm
Fix proposal to deal with diacritics characters
Mark,
Diacritics does not seem to convert appropriately. I suggest to change the two following handlers to:
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
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
Thanks! Hope this helps...
iMed Editor
-
- Posts: 12
- Joined: Fri Apr 21, 2006 1:53 pm
two bugs ?
In the two following functions :
It appears that the first of the three following lines should be changed from:
to:
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)
Code: Select all
private function jObjectToArray
private function jArrayToArray
Code: Select all
repeat while sIndex <= sNumTokens
add 1 to sIndex
switch sJson[sIndex]
Code: Select all
repeat while sIndex < sNumTokens -- and not: <=
Code: Select all
switch sJson[sIndex]
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)
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact: