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)



// 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 on April 19, 2019.
Add Comment

Your Answer

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