jsonactionscript-2

parse json in as2


I need to load and parse some JSON in flash, AS2. The problem is the parsin. It seems that i cant get out what i want from the object. Its a one level object and below you can see how it looks like filled with some dummy text.

My JSON object looks like this:

[
{
    data    
},
{
    data
}
]

Now, how do i parse this in as2? And is it possible? I have only done it in as3 before. I think what i need is some sort of code how to acually load and parse it in as2


Solution

  • You could try this (just tested it with AS2, and seems to work):

    http://inner.geek.nz/archives/2007/01/18/loading-json-in-actionscript-2/

    http://web.archive.org/web/20111014093347/http://inner.geek.nz/uploads/JSON.as

    Usage:

    try {
      var o:Object = JSON.parse(jsonStr);
      var s:String = JSON.stringify(obj);
    } catch(ex) {
      trace(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }