0

I've been looking all over for the solution to this problem, but everything I try always returns the same error.

Fatal error: Cannot use object of type stdClass as array

This is the JSON resource I'm trying to access with PHP cURL: https://www.easports.com/iframe/fifa16proclubs/api/platforms/PS4/clubs/36881/members

The issue I'm having is accessing the raw array. I've had success using the following code with objects, but I always have trouble when there is an array involved.

$phpObj = json_decode($json);

if (!is_null($phpObj->raw))
{   
    $object = $phpObj->raw;

    foreach ($object as $obj)
    {
       echo "<tr id='clubs-search-result'><td class='club-search-name'>" . $obj->name . "</td><td class='blaze-id hidden'>" . $obj->blazeId . "</td><td><button type='button' class='form-button players-search-button red-bg'>Select</button></td></tr>";
    }
}

I know that this is not the correct way to access an array, which is what I need help with. I want to be able to access the raw array and then iterate through all the objects inside the array. I've looked at many code examples but nothing seems to be working for my scenario.

The above code works with this resource: http://www.easports.com/iframe/fifa16proclubs/api/platforms/PS4/clubsComplete/United

Only because I'm accessing nested objects and there are no arrays [] involved.

Any help would be appreciated. Thanks!

1 Answer 1

1

It appears the foreach loop needs to run on the first (and only) array in $phpObj->raw.

You need to change the foreach to:

foreach ($object[0] as $obj) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.