在php中我有这样的东西:
$i=1;
foreach ($result as $row){
$outp['fields'][$i]['id']=$row['id'];
$outp['fields'][$i]['x']=$row['x'];
$outp['fields'][$i]['y']=$row['y'];
$outp['fields'][$i]['type']=$row['type'];
$i++;
}
echo json_encode($outp)
在 JS 中:
success: function(data) {
var map = eval('(data)');
}
这是 JSON 输出:
{"fields":
{"1":{"id":9521,"x":21,"y":96,"type":2},
"2":{"id":9522,"x":22,"y":96,"type":3},
"3":{"id":9523,"x":23,"y":96,"type":1},
"4":{"id":9930,"x":30,"y":100,"type":3}
}
}
我想为每个字段(在这种情况下为 4 个字段)编写 html 代码。我该怎么做?这可以将 var map 转换为数组吗?
谢谢