我尝试将JSON结果(二维数组)转换为Action Script 3中的二维数组,但是出了点问题。有人能帮我吗 ?
我的JSON结果是:
{"area:": [[3, 3, 7], [18, 15, 2], [12, 8, 5], [13, 1, 3], [2, 15, 4], [7, 12, 3]]}
我的As3代码是:
function completeHandlerGetAreas(e:Event):void
{
try
{
var result:Object = JSON.decode(e.target.data);
var array:Array = result.area;
trace(array[0][0]);
}
catch (e:Error)
{
trace('ERROR - Nao foi possivel decodificar o getAreas!');
}
}
答案 0 :(得分:0)
试试这个:
var received_data = '{"area" : [[3, 3, 7], [18, 15, 2], [12, 8, 5], [13, 1, 3], [2, 15, 4], [7, 12, 3]]}'
// ¨¨¨¨ note here that is "area" and not "area:"
try {
var result:Object = JSON.parse(received_data);
var array:Array = result.area
trace(array[4][1]) // it must give : 15
}
catch (e:Error) {
trace('error : '+e.toString())
}