Because I blew a few hours trying to figure this out the last few days, and finally cracking it, here’s how to fetch some JSON from a web service and have it processed into an object in ActionScript 2.
import JSON; // http://www.theorganization.net/work/jos/JSON.as
var jsonFetcher:LoadVars = new LoadVars();
jsonFetcher.onLoad = function(success:Boolean) {
if (!success) {
trace("Error connecting to server.");
}
};
jsonFetcher.onData = function(thedata) {
// ...
// if writing a desktop app or widget, string manip or regexp
// the JSON data packet out of the JS source provided by many
// web services at this point..
// ...
try {
var o:Object = JSON.parse(thedata);
//mytrace(print_r(o));
trace(print_a(o));
} catch (ex) {
trace(ex.name+":"+ex.message+":"+ex.at+":"+ex.text);
}
};
// get the feed
jsonFetcher.load("url-to-json-feed.php");
// from: http://textsnippets.com/posts/show/633
// recursive function to print out the contents of an array similar to the PHP print_r() function
//
function print_a(obj, indent) {
if (indent == null) {
indent = "";
}
var out = "";
for (item in obj) {
if (typeof (obj[item]) == "object") {
out += indent+"["+item+"] => Objectn";
} else {
out += indent+"["+item+"] => "+obj[item]+"n";
}
out += print_a(obj[item], indent+" ");
}
return out;
}
BTW, what’s up with these JSON feeds that serve up JS that’s JSON plus some more code? That’s annoying — you gotta strip it out before you run the JSON converter
.
Update: here’s the actionscript 2.0 JSON.as file people were looking for.

I have been trying to get the as2 json file for a while but the file is missing off the server. I dont suppose you could email it over could you.
I have been trying this address:
http://www.theorganization.net/work/jos/JSON.as
Thanks
#1: Comment by Boxey — January 24, 2007 @ 2:17 am
I have an error with this file (http://www.theorganization.net/work/jos/JSON.as)
#2: Comment by Tanie linie lotnicze — January 26, 2007 @ 10:51 pm
You can get that AS file here:
http://inner.geek.nz/uploads/JSON.as
#3: Comment by Brett
Twitter: glutnix
— January 30, 2007 @ 4:27 pm
Brett thanks for help it works at my site.
Keep up the good work.
Greetings
#4: Comment by Pozycjonowanie — January 31, 2007 @ 1:50 am
Fantastic code. Work great on my site. Again thanks and greetings
#5: Comment by Meble — February 10, 2007 @ 2:52 am
Can you please provide the JSON File you are using as an example?
#6: Comment by Alex — February 15, 2007 @ 6:40 am
the script causing the flash player run slowly… please provide the working as and fla file.
#7: Comment by james — May 1, 2007 @ 2:32 am
Thank yoy it was really helpful especially for my boyfriend because he’s been looking for stuff like that for weeks!
#8: Comment by Tanie tłumaczenia — October 2, 2007 @ 5:15 am
Thank you so much! I’ve been trying to figure this out for the past 2 days. The original class files from json.org and examples I found online were terrible. I was able to load and stringify, but it gave me no solution to extrapolate the values. With your example, I was easily able to just convert the whole thing into an array. Thanks again.
#9: Comment by Jeff — December 19, 2008 @ 9:01 am
absolutely awesome. I just spent 3 hours looking for exactly the code you got here, all other code examples out there were crap
#10: Comment by Robert — August 14, 2009 @ 8:36 am