【发布时间】:2013-08-21 14:16:58
【问题描述】:
我有一个数组,比如:
[['jkjhkfhkjh jkj jkjhk', '54.324705', '-2.749629', '189', 1, 1, 0, 0, 'Test two', '2 ', '10+', 'http://xx.co.uk/xx/?post_type=listings&amp;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 &nbsp;fghfg hf dfh dfh', '54.323174', '-2.744554', '188', 1, 1, 0, 0, 'Test', '2 ', '10+', 'http://xx/xx/?post_type=listings&amp;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();
似乎可以很好地转换为控制台,但它是以文本而不是数组的形式出现的。我怎样才能把它变成一个数组?
【问题讨论】:
-
您如何检索 JSON?
-
HTML 不支持数组,所以当然是文本?
-
@JasonMcCreary 我只是以 javascript 数组的格式回显了一些数据
-
@adeneo 是的,我不确定如何翻译。我试过 .text() 但同样,它不是一个数组。如何将它作为数组带入我的 js 中?
-
显示您正在回显的行。
标签: php javascript jquery arrays