我有这个:

    (65.94647177615738,87.890625)(47.040182144806664,90)(45.089035564831036,122.34375)


我试图使输出看起来像这样:

   “坐标”:[[65.94647177615738,87.890625],[47.040182144806664,90],[45.089035564831036,122.34375]]


任何的想法?

第一个结果以字符串形式返回给我,因此当我尝试将第一个对象分配给数组时,控制台将向我显示以下内容:

  数组是:“((65.94647177615738,87.890625)(47.040182144806664,90)(45.089035564831036,122.34375)”

最佳答案

var str = "(65.94647177615738, 87.890625)(47.040182144806664, 90)(45.089035564831036, 122.34375)";
str = str.slice(1,-1); // remove outermost parentheses
var arrCoord = str.split(')(');
for (var i=0; i<arrCoord.length; i++) {
    var tarr = arrCoord[i].split(", ");
    for (var j=0; j<tarr.length; j++) {
        tarr[j] = parseFloat(tarr[j]);
    }
    arrCoord[i] = tarr;
}
// arrCoord is now populated with arrays of numbers

09-13 12:29