Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS JSON的JavaScript解析部分_Javascript_Json_Angularjs - Fatal编程技术网

AngularJS JSON的JavaScript解析部分

AngularJS JSON的JavaScript解析部分,javascript,json,angularjs,Javascript,Json,Angularjs,我有以下JSON。 我要给出一个参数,我需要返回所有的数字 如果我给“巴士”,我需要返回1,38,44,58 JSON示例: { _id:"23456789", result:[ [ "Car", [ [ 2, 3, 4, 6 ],

我有以下JSON。 我要给出一个参数,我需要返回所有的数字

如果我给“巴士”,我需要返回1,38,44,58

JSON示例:

{  
   _id:"23456789",
   result:[  
      [  
         "Car",
         [  
            [  
               2,
               3,
               4,
               6
            ],
            [  
               3,
               4,
               444,
               123
            ],
            [  
               43,
               34,
               91446,
               344473
            ]
         ]
      ],
      [  
         "Bus",
         [  
            [  
               1,
               38,
               4458,
               0981
            ]
         ]
      ],
      [  
         "Moto",
         [  
            [  
               5,
               43,
               41440,
               804444
            ]
         ]
      ]
   ]
}
这是我的代码:

    var coordinates = [];
    console.log("tag :"+tag); // tag is the parameter "Bus", "Car" or "Moto"
    $http.get('http://myserver:1234/bbox/'+id)
                    .success(function (response) {
                var point = {};
                // Don't know how to catch a specific word (i.e Car or BUS or Moto)
                for (var i in response){
                    var pointName =  response.result[i][0];
                    coordinates.push(response.result[i][1]);
                    points[pointName] = coordinates;
                }

    })
    .error(function (response) {
        console.log(response);
     });
标记
仅使用一个参数设置。 只需要返回一个给定的坐标


谢谢你的帮助

这对于JSON响应来说是非常奇怪的结构,但您仍然可以提取必要的数据。例如,使用
Array.prototype.filter
方法:

var coordinates = response.result.filter(function(el) {
    return el[0] === tag;
})[0][1][0];

对于
标记
等于“总线”,上述代码将为您提供
[1,38,4458,981]
数组。

谢谢您的回复。我可以做一些类似var坐标=响应.结果.过滤器(函数(el){var res=el[0]==tag;console.log(“res”+res);})[0][1][0]????我不太明白。过滤器必须返回布尔值。哦,我错了,它工作了!关于标记“Car”,我还将获取所有点?看起来您实际上需要
filter()[0][1]
来获取所有点数组(所有点数组的数组)。