1

I'm using curl to receive a json object but I'm having problem to convert it and iterate it to insert in database.

I start to decode the information received:

$response = json_decode(curl_exec($curl), true);

and it return this:

array(1) { ["d"]=> string(14033) "[{"casa":181,"id":"8892","nome":"XPTO","morada":"rua 1"}]"

Next I access to "d" because I don't need that:

$resp =  $response["d"];

and it returns this:

"[{"casa":181,"id":"8892","nome":"XPTO","morada":"rua 1"}]"

How can why iterate this with " "?

What is the better way to do that?

Thank you

1 Answer 1

3

You can do double decode because your curl response is double encoded, Do it this way-

$response = json_decode(curl_exec($curl), true);
$resp = json_decode($response['d'], true);
Sign up to request clarification or add additional context in comments.

1 Comment

As they can already access $response["d"], it looks as though you only need to decode this rather than decoding the whole thing twice.

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.