php - convert json_encode data to javascript array -


i send data php json_encode javascript. data

[{"albumid":"asabfzctl8","albumname":"anni","type":"3","access":"2","itemcount":"2"},{"albumid":"emgsz43eht","albumname":"testalbum","type":"1","access":"1","itemcount":"0"},{"albumid":"jf4h4svfgk","albumname":"test2album","type":"3","access":"1","itemcount":"0"},{"albumid":"k3pacbsmil","albumname":"testalbumpvt","type":"3","access":"2","itemcount":"0"}] 

after enoding in php

       //json_encode($data);  "[{\"albumid\":\"asabfzctl8\",\"albumname\":\"anni\",\"type\":\"3\",\"access\":\"2\",\"itemcount\":\"2\"},{\"albumid\":\"emgsz43eht\",\"albumname\":\"testalbum\",\"type\":\"1\",\"access\":\"1\",\"itemcount\":\"0\"},{\"albumid\":\"jf4h4svfgk\",\"albumname\":\"test2album\",\"type\":\"3\",\"access\":\"1\",\"itemcount\":\"0\"},{\"albumid\":\"k3pacbsmil\",\"albumname\":\"testalbumpvt\",\"type\":\"3\",\"access\":\"2\",\"itemcount\":\"0\"}]" 

i receiving in jquery

$.post("demo.php",   {     token:"123456789"   },   function(data,status){     alert("data: " + data + "\nstatus: " + status);   }); 

what can data in javascript array need type value out of , looking

var typevalue = jsonarray['type']; // typevalue = 3 

assuming have parsed json here's how loop it:

$.each(data, function(key, album){     console.log(album.type); }); 

to grab first type in list do:

var albumtype = data[0].type; 

full solution parsing:

$.post("demo.php", {     token: "123456789" },  function (data, status) {     $.each(data, function (key, album) {         alert(album.type);     });  }, "json"); //datatype defined here 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -