How to convert a string to JSON object php?

Convert a string to JSON object php

Default Asked on April 5, 2019 in JSON.
Add Comment
1 Answer(s)

 

<?php

// JSON string

$JSON = '[{"name":"Suman","gender":"male"},{"name":"William","gender":"male"},{"name":"Sara","gender":"female"}]';
// Convert JSON string to Object

$someObject = json_decode($JSON);

print_r($someObject); // Dump all data of the Object

echo $someObject[0]->name; // Access Object data

?>

 

Team Leader Answered 7 days ago.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.