Javascript(Appcelerator Titanium)多维数组解析不起作用

Boo*_*App 0 javascript arrays parsing multidimensional-array

解析多维数组时遇到问题,我从facebook得到这个答案:

e.result我有这样的:

{
   "data":[
        {
         "name":"Linda Kase",
         "id":"1393034660999695"
        },
        {
         "name":"Dick Typ",
         "id":"1376046576034204"
        },
        {
         "name":"a a",
         "id":"1388801108093951"
        },
        {
         "name":"b b",
         "id":"1382328532076389"
        }
     ],
   "paging": {
        "next":"https:\/\/graph.facebook.com\/v2.2\/1378163649155341\/friends?format=json&access_token=XXXXXXXXXXXXXXXXXXX"
     },
   "summary":{
            "total_count":8
         }
}
Run Code Online (Sandbox Code Playgroud)

这是我解析它的代码:

Ti.App.fb.requestWithGraphPath('me/friends',false, 'GET', function(e){
    if(e.success){
        var result = e.result;
        alert(result.data[0].name);
    }
});
Run Code Online (Sandbox Code Playgroud)

我总是接受这个:

未捕获的TypeError:无法读取未定义的属性"0"

任何人都知道它为什么不起作用?我也试图JSON.stringifyJSON.parsee.result

谢谢!

小智 5

你必须使用:

    var result = JSON.parse(e.result);
    alert(result.data[0].name);
Run Code Online (Sandbox Code Playgroud)

因为你把它作为一个字符串,而不是一个数组