Daniii Posted December 14, 2020 Share Posted December 14, 2020 <?php $1 = file_get_contents(""); $2 = json_decode($1); $3 = $2->result; var_dump($myData1); foreach($3 as $key => $item): echo $item->Users->UserObject->UserName; endforeach; ?> { "result": [ { "ID": 1, "Users": [ { "UserObject": { "UserName": "test1" }, "...": 2 }, { "UserObject": { "UserName": "test2" }, "...": 2 } ], "IsActive": true } ], "error": false } I get this error Notice: Trying to get property 'UserObject' of non-object in C:\xampp\htdocs\dashboard-master\chart.php on line 10 Notice: Trying to get property 'UserName' of non-object in C:\xampp\htdocs\dashboard-master\chart.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/311858-help-with-file_get_contents/ Share on other sites More sharing options...
NotionCommotion Posted December 14, 2020 Share Posted December 14, 2020 $item->Users is an array. Try $item->Users[$key]->UserObject->UserName; PS. Recommend changing your variable names to something other than $1, etc. Quote Link to comment https://forums.phpfreaks.com/topic/311858-help-with-file_get_contents/#findComment-1583063 Share on other sites More sharing options...
Daniii Posted December 14, 2020 Author Share Posted December 14, 2020 It works but i get only one user i would get teest1 and test2 Quote Link to comment https://forums.phpfreaks.com/topic/311858-help-with-file_get_contents/#findComment-1583064 Share on other sites More sharing options...
NotionCommotion Posted December 14, 2020 Share Posted December 14, 2020 Try adding var_dump($key) and var_dump($item) in your loop so you know what you are looking at. Quote Link to comment https://forums.phpfreaks.com/topic/311858-help-with-file_get_contents/#findComment-1583065 Share on other sites More sharing options...
Daniii Posted December 14, 2020 Author Share Posted December 14, 2020 I do this with an jsonpathfinder Quote Link to comment https://forums.phpfreaks.com/topic/311858-help-with-file_get_contents/#findComment-1583066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.