javascript - get values in pairs from json array -
firstly, json value getting php source:
[{"oid":"2","cid":"107"},{"oid":"4","cid":"98"},{"oid":"4","cid":"99"}]
after that, want , oid
value along corresponding cid
value example, oid=2
, cid=107
@ 1 go, oid=4
, cid=98
@ , on. trying use jquery, ajax this.
i have tried many answers this, like: javascript: getting existing keys in json array , loop , key/value pair json array using jquery don't solve problem.
i tried this:
for (var = 0; < l; i++) { var obj = res[i]; (var j in obj) { alert(j); }
but did return key name, again did not work on being used.
so, have array of key/value pairs. loop array, @ each index, log each pair:
var obj = [{"oid":"2","cid":"107"},{"oid":"4","cid":"98"},{"oid":"4","cid":"99"}]; (var = 0; < obj.length; i++) { console.log("pair " + + ": " + obj[i].oid); console.log("pair " + + ": " + obj[i].cid); }
Comments
Post a Comment