fightstarr20
fightstarr20

Reputation: 12608

Python - Flask API response cant json_decode

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?

Upvotes: 0

Views: 173

Answers (2)

GRoutar
GRoutar

Reputation: 1425

json_decode has a 2nd argument to return an array:

$response = json_decode($response, true);

Upvotes: 1

Kannappan Sirchabesan
Kannappan Sirchabesan

Reputation: 1382

try this

json_decode($response->result_array());

Upvotes: 1

Related Questions