0
votes

hey i've tried to DECODE my JSON data like this : `

$json = file_get_contents("http://localhost/php/service.php?rquest=searcht&user=".$user);
$final_res = html_entity_decode($json);
foreach ($final_res as $thedata->user)
            {
            foreach ($thedata as $value) { ?>
          <tr>
            <td  ><? echo $value['No']?>  </td>
            <td><?echo $value['user']?></td>
   }
}

` the decode data works fine with output JSON, but when i tried to foreach the JSON data, its doesnt work, but..in other case i use this foreach the same way to print my data with Select * data query to other page. its work, but i use this foreach to same way, but the output is Invalid argument supplied for foreach() please tell me if i do a mistake...

1
Try var_dump() to see what kind of data the parameter is which you are passing to the foreach() loop. - Daniel K.
where are you decoding the json? that doesn't have a call to json_decode at all. - Jonathan Kuhn
update i've been decode like this : $final_res = html_entity_decode($json); $final_res1 = json_decode(stripslashes($final_res)); but foreach doesnt work - user3511548
then the result is NULL when i try json_decode - user3511548

1 Answers

0
votes

you have not used json_decode, the content you are getting from file_get_contents is a string, apply json_decode($final_res) to get the content in an array form.