简体   繁体   中英

How to read JSON object in PHP?

I want to read status and message object of this JSON.
I have tried json_decode() but its not working fine.

JSON:

{"d":"{\"successMessage\":\"24 rows added / updated\",\"failMessage\":null,\"status\":true}"}

please use the following code

$json = '{"d":"{\"successMessage\":\"24 rows added / updated\",\"failMessage\":null,\"status\":true}"}';

echo "<pre>";
$myArr = json_decode($json, true);
$varArr = json_decode($myArr["d"]);
print_r($varArr)."<hr>";
echo $varArr->successMessage;

and it will give output as

stdClass Object
(
    [successMessage] => 24 rows added / updated
    [failMessage] => 
    [status] => 1
)
24 rows added / updated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM