[ create a new paste ] login | about

Link: http://codepad.org/Gtk8DqJE    [ raw code | output | fork | 1 comment ]

PHP, pasted on Dec 3:
<?php

$json = <<< JSON
{
    "John": {
        "status":"Wait"
    },
    "Jennifer": {
        "status":"Active"
    },
    "James": {
        "status":"Active",
        "age":56,
        "count":10,
        "progress":0.0029857,
        "bad":0
    }
}
JSON;

$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($json, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
    if(is_array($val)) {
        echo "$key:\n";
    } else {
        echo "$key => $val\n";
    }
}


Output:
1
2
3
4
5
6
7
8
9
10
John:
status => Wait
Jennifer:
status => Active
James:
status => Active
age => 56
count => 10
progress => 0.0029857
bad => 0


Create a new paste based on this one


Comments:
posted by bemita on Aug 7
"Bemita": {
"status":"Active",
"age":22,
"count":10,
"progress":0.0029857,
"bad":0
}
reply