2014-10-30 65 views
0

我試圖在Action Script 3中將一個JSON結果(二維數組)轉換爲二維數組,但出現了一些錯誤。有人能幫我嗎 ?將JSON二維數組轉換爲AS3數組

我的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

試試這個:

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()) 
} 
+0

太謝謝你了!正常工作! – avells 2014-11-01 19:06:42