how to parse this json

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sallaudin
Forum Newbie
Posts: 1
Joined: Mon Jan 20, 2014 2:02 pm

how to parse this json

Post by sallaudin »

Code: Select all

$json = '{"Data":{"Date":"08:09 20-01-2014","SchoolID":"923214157777","Type":"1","Nic":["3520135201001","3520135201002","3520135201003"]}}';
$main_array=json_decode($json);
foreach($main_array->Data as $key=>$value ) {
 if(is_array($value)) {
        echo "$Date:\n";
    } else {
        echo "$key => $value\n";
    }
i am using this approach but i want to get the values on the behalf of keys and get all the nic in one go
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: how to parse this json

Post by Christopher »

$main_array->Data->Nic
(#10850)
Post Reply