key value json for loop code example
Example 1: javascript json key value loop
var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
for (var key in p) {
if (p.hasOwnProperty(key)) {
console.log(key + " -> " + p[key]);
}
}
Example 2: php json key value loop
$json = '{"1":"a","2":"b","3":"c","4":"d","5":"e"}';
$obj = json_decode($json, TRUE);
foreach($obj as $key => $value)
{
echo 'Your key is: '.$key.' and the value of the key is:'.$value;
}