Leonard Febrianto Leonard Febrianto - 20 days ago 7
jQuery Question

Loop JSON Data after Succes from Ajax

I have a JSON data looks like this :

{
"kode_pesanan":"P000000033",
"lat":"4.454274",
"lng":"96.152699",
"sort":0,
"gambar":"\/status_image\/persiapanbiru.png"
}


This is the
json_encode
:

echo json_encode(
array(
"kode_pesanan"=>$data['kode_pesanan'],
"lat"=>$data['lat_antar'],
"lng"=>$data['ltd_antar'],
"sort"=>$i,
"gambar"=>$status
)
);


I have trying with
for
and
$.each
statements but didn't work.

What am I missing ?

Answer

Try this:

var json = {"kode_pesanan":"P000000033","lat":"4.454274","lng":"96.152699","sort":0,"gambar":"\/status_image\/persiapanbiru.png"}
console.log(json);
//json = $.parseJSON(json);
$.each( json , function(e,v) {
	console.log(e,v);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

$.each( json , function(e,v) => e is the key and v is the value of the json object

Comments