Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
Jquery:遍历当前为字符串的嵌套列表_Jquery_Json - Fatal编程技术网

Jquery:遍历当前为字符串的嵌套列表

Jquery:遍历当前为字符串的嵌套列表,jquery,json,Jquery,Json,我有以下JSON结构: "data":[ { "Status":"", "Description":"SDH Source: http://www.flickr.com/photos/ssong/5980312175/ Parts of this are highly speculative and probably wrong.", "Country":"Botswana", "Route":"Ghanzi - Namibia border", "__id__":1, "Operator":"

我有以下JSON结构:

"data":[
{
"Status":"",
"Description":"SDH Source: http://www.flickr.com/photos/ssong/5980312175/ Parts of this are highly speculative and probably wrong.",
"Country":"Botswana",
"Route":"Ghanzi - Namibia border",
"__id__":1,
"Operator":"",
"Linestring":"[[21.655687226945439,-21.69807092918915],[21.606544897735219,-21.698981514014829],[21.55814494317222,-21.6948413352827],[21.492934687173641,-21.70172591790476],[21.432925637207919,-21.707152166982251],[21.4108749703861,-21.712328345347341],[21.38092408696798,-21.733997442781551],[21.33297121701732,-21.737244186092511],[21.270621127018181,-21.7492165472962],[21.209296018166889,-21.760407028676049],[21.184802907584931,-21.7673550397231],[21.124295475909431,-21.77495082482249],[21.036772532878931,-21.902107946653949],[21.030922147053559,-21.92655934013332],[21.029823515972719,-21.939804388740249],[21.024525846876742,-21.946069573594141],[20.999362774212379,-21.947996797946232]]"
},
{
"Status":"",
"Description":"SDH Source: http://www.flickr.com/photos/ssong/5980312175/ Parts of this are highly speculative and probably wrong.",
"Country":"Botswana",
"Route":"Main Loop",
"__id__":2,
"Operator":"",
"Linestring":"[[25.868245525590559,-24.659437558460471],[25.839065125037649,-24.636438708648949],[25.8304766089291,-24.63941684823082],[25.764698657054229,-24.652354808830591],[25.66910795259367,-24.65864351524873],[25.621786791268288,-24.690836785084102],[25.525336477796891,-24.688237872812209],[25.439770053803031,-24.762743692863971],[25.388036603028329,-24.834169218942151],[25.34840467511296,-24.907043674808271],[25.295372125100659,-24.95527683356271],[25.041334775867188,-24.824558772828009],[24.881696518620149,-24.718259087968971]]"
} ]

我希望遍历JSON,检索每个Linestring值并插入到google地图中。不幸的是,因为Linestring值是一个字符串,所以我在遍历它时遇到了问题。我尝试过使用eval()方法和$.parseJSON方法,但没有成功,代码似乎重复了不止一次,所以我得到了一个混乱的映射

function OnLoad() {
  var my_array;
  var coords;
  var points = [];
  $.getJSON(url, function (data) {
   $.each(data.data, function(key,val){
       my_array = eval('(' + data.data[count].Linestring + ')');
       for (j = 0; j<linestring_array[count].length;j++){
    coords = linestring_array[j];
            points.push(new google.maps.LatLng(coords[1], coords[0]));
       }
            }
   });
 });
函数OnLoad(){
变量my_数组;
var-coords;
var点=[];
$.getJSON(url、函数(数据){
$.each(data.data,function(key,val){
my_array=eval('('+data.data[count].Linestring+');
对于(j=0;j,这将帮助您(和其他评论者)走出困境

函数OnLoad(){
变量my_数组;
var-coords;
var点=[];
$.getJSON(url、函数(数据){
$。每个(数据、函数(键、值){
var my_array=$.pareJSON(val.Linestring),points=[];

对于(var j=0;jEval it?或者split/parse it.crolpa)我尝试了这段代码,我在前面编写了一段类似的代码。代码似乎可以正常工作,只是加载了一些JSON提要中不存在的值。我不知道它们来自何处
  function OnLoad() {
          var my_array;
          var coords;
          var points = [];
          $.getJSON(url, function (data) {
                 $.each(data, function(key,val){
                        var my_array = $.pareJSON(val.Linestring),points=[];
                        for (var j = 0; j<my_array.length;j++){
                               var coords = my_array[j];

                               //you'll have to check up on the correct usage of google.maps api
                               points.push(new google.maps.LatLng(coords[1], coords[0]));
                        }
                        console.log(points);
                 });
          });
   };