0

我可以从我的 C# 代码中返回这个字符串。我需要实施谷歌地图。如何将其转换为数组。

细绳

var array = [["Andover - Wyevale Garden Centre","Concession A","Andover Garden Centre","Salisbury Road","Andover","SP11 7DN","01264 710114","14.9 miles","51.1998552","-1.5111393"],
    ["Portsmouth - Gunwharf Quays","Unit 29","Gunwharf Quays","Portsmouth","Hampshire","PO1 3TZ","02392 819558","20.8 miles","50.7963663","-1.1065603"],
    ["Chichester","83 North Street","Chichester","West Sussex","PO19 1LQ","01243 380058","25.9 miles","50.837269","-0.77846"],
    ["Newport - Isle of Wight","117/119 High Street","Newport","Isle of Wight","PO30 1TP","01983 527485","27.1 miles","50.700399","-1.294872"],
    ["Guildford","20-21 North Street","Guildford","Surrey","GU1 4AF","01483 456978","29.8 miles","51.2369881","-0.5731617"]]

我不知道,但是当我这样做时,array[1][0]它应该Portsmouth在 chrome 控制台中返回“”,但它会以undefined.

我怀疑数组变量被标识为字符串而不是数组。

当我这样做时,array[0][4]我得到“A”作为输出。

请帮忙

4

3 回答 3

3

使用这个..这将在我身边运行。

var array = '[["d","ddd","sadasd","Salisbury Road","Andover","SP11 7DN","01264 710114","14.9 miles","51.1998552","-1.5111393"],["Portsmouth - Gunwharf Quays","Unit 29","Gunwharf Quays","Portsmouth","Hampshire","PO1 3TZ","02392 819558","20.8 miles","50.7963663","-1.1065603"],["Chichester","83 North Street","Chichester","West Sussex","PO19 1LQ","01243 380058","25.9 miles","50.837269","-0.77846"],["Newport - Isle of Wight","117/119 High Street","Newport","Isle of Wight","PO30 1TP","01983 527485","27.1 miles","50.700399","-1.294872"],["Guildford","20-21 North Street","Guildford","Surrey","GU1 4AF","01483 456978","29.8 miles","51.2369881","-0.5731617"]]'



var arrayObj = JSON.parse(array)
console.log(arrayObj)
console.log(arrayObj[1][0])

// 返回--- 朴茨茅斯 - Gunwharf Quays

于 2013-08-14T10:31:00.950 回答
1

好的试试这个:

var array = [["Andover - Wyevale Garden Centre","Concession A","Andover Garden Centre","Salisbury Road","Andover","SP11 7DN","01264 710114","14.9 miles","51.1998552","-1.5111393"],
    ["Portsmouth - Gunwharf Quays","Unit 29","Gunwharf Quays","Portsmouth","Hampshire","PO1 3TZ","02392 819558","20.8 miles","50.7963663","-1.1065603"],
    ["Chichester","83 North Street","Chichester","West Sussex","PO19 1LQ","01243 380058","25.9 miles","50.837269","-0.77846"],
    ["Newport - Isle of Wight","117/119 High Street","Newport","Isle of Wight","PO30 1TP","01983 527485","27.1 miles","50.700399","-1.294872"],
    ["Guildford","20-21 North Street","Guildford","Surrey","GU1 4AF","01483 456978","29.8 miles","51.2369881","-0.5731617"]];
于 2013-08-14T10:28:07.347 回答
1

尝试删除包含双引号并包含终止分号;...

var array = [["Andover - Wyevale Garden Centre","Concession A","Andover Garden Centre","Salisbury Road","Andover","SP11 7DN","01264 710114","14.9 miles","51.1998552","-1.5111393"],
    ["Portsmouth - Gunwharf Quays","Unit 29","Gunwharf Quays","Portsmouth","Hampshire","PO1 3TZ","02392 819558","20.8 miles","50.7963663","-1.1065603"],
    ["Chichester","83 North Street","Chichester","West Sussex","PO19 1LQ","01243 380058","25.9 miles","50.837269","-0.77846"],
    ["Newport - Isle of Wight","117/119 High Street","Newport","Isle of Wight","PO30 1TP","01983 527485","27.1 miles","50.700399","-1.294872"],
    ["Guildford","20-21 North Street","Guildford","Surrey","GU1 4AF","01483 456978","29.8 miles","51.2369881","-0.5731617"]];
于 2013-08-14T10:17:37.310 回答