0

I have built a very simple Python API using flask, my response looks like this...

response = {
    "id" : "345345d",
    "topdata" : {
        "top"    : 234,
        "left"   : 42,
    },
    "bottomdata" : {
        "color" : "red",
        "bg" : "black",
    },
}

return jsonify(response)

I then try and decode that response in my PHP script like this...

$response = json_decode($response);

But this gives me the following error..

Cannot use object of type stdClass as array

Anyone any ideas where I am going wrong?

1
  • Did you try examining the contents of $response before sending it to json_decode? Does it look like valid JSON? Does it look like what you expected it to be? Commented Jan 20, 2019 at 14:00

2 Answers 2

1

json_decode has a 2nd argument to return an array:

$response = json_decode($response, true);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that fixed things
1

try this

json_decode($response->result_array());

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.