when I try to convert a Collectio <?> JAVA, in this case a List<JSONObject>, in ActionScript Array, the conversion fails and returs me null.
I have a ServerSide JAVA Extension that sends to the client a message with JSONObject format, composed in this manner (I lightened the code and entered fictitious information, the list is long but already it gives me error):
Code: Select all
String username = "pippo";
List<JSONObject> listColor = new ArrayList<JSONObject>();
JSONObject color1 = new JSONObject();
color1 .put("description", "black");
listColor.add(color1 );
JSONObject jsonMsg = new JSONObject();
jsonMsg.put("username", username);
jsonMsg.put("listColor", listColor);
When the client receives the message, printing the contents without Array cast, I get this:
Code: Select all
pippo
[{"description":"black"}]
With this code
Code: Select all
private function onExtensionResponse(e:SFSEvent):void{
var data:Object = e.params.dataObj;
trace(data.username);
trace(data.listColor);
}
Now if I would only get the value "descrition" of the first color object, I tried to first cast to Array, but I get null:
With this code
Code: Select all
private function onExtensionResponse(e:SFSEvent):void{
var data:Object = e.params.dataObj;
trace(data.username);
var arrayColor:Array = data.listColor as Array;
trace(arrayColor);
}
pippo
null
I also tried this type cast Array(data.listColor) but the result is the same. Consequently, attempting to enter the first item:
Code: Select all
trace(data.username);
var arrayColor:Array = data.listColor as Array;
trace(arrayColor[0]); // or arrayColor["descritpion"]
all crashes (obviously because it is null):
Why? How i can convert a Collection JAVA?