这是一个艰难的过程,至少对我来说。所以基本上我想做的是通过Javascript获取这个JSON数据每一行的每一个值:
{"id":2,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":3,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":4,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":5,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":6,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":7,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":8,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":9,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":10,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":31,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":32,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":33,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":34,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":35,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":36,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":37,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":38,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":39,"url":"image.png","x":19,"y":10,"user_id":20}
{"id":40,"url":"image.png","x":19,"y":10,"user_id":20}
我以这种方式生成它(在我的 PHP 文件中):
$db->where('user_id', '20');
$results = $db->get('profile_stickers');
foreach ($results as $parameters => $values) {
echo json_encode($values);
}
我已经尝试了很多与 jQuery 相关的代码,$.each
但没有运气,代码永远不会工作。我想获得每个值,因为我将在页面上显示它们,并具有正确的位置和图像。有谁知道获取每一行的正确功能?像 PHP 的$row['foo']
.
- - - 编辑 - - -
我是这样做的:
$.get('/Application/Ajax/__ajaxProfile.php?a=GetWidgets', function(data) {
var json = data;
for (i=0;i<json.length;i++){
var obj = json[i];
for (var key in obj) {
document.getElementById("log").innerHTML += key+": "+obj[key]+"<br />";
}
document.getElementById("log").innerHTML += "<br />";
}
});
但问题是,它返回的数据如下:
0: " 0: [ 0: { 0: i 0: d 等等。
- - 编辑 - - -
现在修复了,它是“$.get”的东西。