For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Friday, February 05, 2016

JSON parse in PHP

JSON parse in PHP



Suppose you want to parse listed below JSON data in PHP and you only needed to print objectId values. you can see here 3 records under merchants value "RPEZF3MRM39Z0"

-----------------------------------------------------------------------
{
"appId": "0QA16KMMVJAQR",
"merchants": {
"RPEZF3MRM39Z0": [{
"objectId": "O:S1MXC6FCY6GDW",
"type": "UPDATE",
"ts": 1453110818494
}, {
"objectId": "O:S1MXC6FCY6GDW",
"type": "UPDATE",
"ts": 1453110818913
}, {
"objectId": "P:SYD46NHH64EQG",
"type": "CREATE",
"ts": 1453110818913
}]
}
}
------------------------------------------------------------------------

php code:

suppose $st is hlding the above json data.

$json_a=json_decode($st,true);
foreach ( $json_a['merchants']['RPEZF3MRM39Z0'] as $objectId )
{
    echo $objectId['objectId']."</br>";
}




Share:

0 comments:

Post a Comment

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip