I have a string which is in valid Json format and it looks like this:
{
\"message\": \"success\",
\"result\": {
\"46620\": {
\"co
To loop through all the results, something like this should do it:
$obj = json_decode($str);
foreach ($obj->result as $result)
{
$fa_title = $result->fa_title;
$en_title = $result->en_title;
}
In JSON, arrays are designated by brackets ([
and ]
) while dictionaries only have braces ({
and }
).
You could access each result object individually by doing $obj['result']['46620']['en_title']
.
The result object is an associative array (also known as a dictionary) of associative arrays.
You can also iterate through each object using a foreach
loop, as demonstrated in this question