0

I have a JSON response coming up as

[{"serial": "1", "name": "ABC" }]

I am using com.adobe.serialization.JSON class of as3corelib in actionscript. This class works perfectly in other formats of json, but in this case, after doing a JSON.decode to the object I am unable to get the value as obj.name

If I remove the square brackets I am getting a parsing error.

How can I parse the json in this case, I need to get the value of the key "name". Thanks.

2 Answers 2

1

Technically to parse all the objects you'll need

// serverResponse answer from the server [String]
var jsonResponse:Object = JSON.parse(serverResponse);
for ( var object:Object in jsonResponse ){
   trace(object.name);
}

Well as you edited this is using : ActionScript 3 JSON and it's not just for air, you still can use it


And using AS3CoreLib, here is an example showing how to handle the JSON, so it look like this :

var rawData:String = String(event.result);
var arr:Array = (JSON.decode(rawData) as Array);
for (var i:int = 0; i < arr.length; i++){
    trace(arr[i].name);
}

Hope this helps, Cheers !!

Sign up to request clarification or add additional context in comments.

1 Comment

Hi this is for adobe air, and am using the as3corelib.swc
0

You are parsing array of json objects. You need to fetch the value like obj[0].name.

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.