JSONObject in JS - random access output converted to string always null?

I am trying to use JSONObject with Unity JS, but I am running into an interesting problem where I cannot convert the values explicitly into strings (for eventually conversion to float in parseFloat).

        var str = [insert json here]
    
    var j= new JSONObject(str);
    Debug.Log(j[0]["key"]); // outputs the right value!

    var d:String = j[0]["key"] as String; 
    Debug.Log(d); // outputs null !! 

   // resulting parseFloat yields error: ArgumentNullException: Argument cannot be null.

Not sure what’s going on here, but I guess the typecasting is failing and nullifying the data? How do you convert this data to a usable format?

Sorry to post in such an old thread. But if anybody stumbles upon this again it might be useful to them if I’m right.

It seems you’re trying to typecast an Object into a String, as far as I can see you should be able to do this:

var d:String = j[0]["key"].str; 
Debug.Log(d);

That’s what I can see from the documentation:

JSON unity wiki page #Decoding