php,js创建json数据

In php I have something like this:

$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)

And in the JS:

success: function(data) {
  var map = eval('(data)');
}

And here is the JSON output:

{"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}
     } 
}

I want to write html code for every field (4 fields in that case). How can I do it? is this possible to convert var map into array?

Thanks

Try this:

for(var i=1;i<=Object.keys(map["fields"]).length;i++){
    console.log(map["fields"][i]["id"]); //id
    console.log(map["fields"][i]["x"]);  //x
    console.log(map["fields"][i]["y"]);  //y
}