我有一个数组,例如:
[['jkjhkfhkjh jkj jkjhk', '54.324705', '-2.749629', '189', 1, 1, 0, 0, 'Test two', '2 ', '10+', 'http://xx.co.uk/xx/?post_type=listings&p=189', '<img width="160" height="85" src="http://www.xx.com/manage/wp-content/uploads/wheelbase.jpg" class="attachment-thumbnail wp-post-image" alt="wheelbase" title="wheelbase">', '189'],['fghfghfgh fghfg hf dfh dfh', '54.323174', '-2.744554', '188', 1, 1, 0, 0, 'Test', '2 ', '10+', 'http://xx/xx/?post_type=listings&p=188', '<img width="160" height="85" src="http://www.xx.com/manage/wp-content/uploads/wheelbase.jpg" class="attachment-thumbnail wp-post-image" alt="wheelbase" title="wheelbase">', '188']];
我使用 php 获取数据:
echo "[";
for ($i=0; $i < count($json); $i++) {
echo "['" . $json[$i]["content"] . "', '". $json[$i]["lat"] . "', '" . $json[$i]["long"] . "', '" . $json[$i]["id"] . "', 1, 1, 0, 0, '" . $json[$i]["title"] . "', '2 ', '10+', '" . $json[$i]["link"] . "', '<img width=\"160\" height=\"85\" src=\"http://www.xx.com/manage/wp-content/uploads/wheelbase.jpg\" class=\"attachment-thumbnail wp-post-image\" alt=\"wheelbase\" title=\"wheelbase\" />', '" . $json[$i]["id"] . "'],";
}
echo "]";
(我叫了一个变量$json
,忽略我叫它的事实,它不是 json)
所以我将这些回显到一个将被隐藏的 div 中。然后在javascript中拿起它,我试试这个:
var locations = $('#listingsarray').html();
这似乎可以很好地转换为控制台,但它是以文本而不是数组的形式出现的。我怎样才能把它变成一个数组?