0

having parsed an object of nested objects and nested arrays PHP is mixing them up. it works well on some objects but not on others

  $f = json_decode($jsonObject, true);

example of nested objects that php recognises as objects:

enter image description here

examples of arrays which php recognises as objects in arrays:

enter image description here

examples of object which php recognises as an arrays:

enter image description here

if i begin mixing arrays of objects it no longer recognises simple objects, it interprets them as arrays.

how can i get php to fully recognise arrays and objects in JSON,

1
  • 2
    Please use text/code, not images Commented Jul 16, 2019 at 13:19

1 Answer 1

1

You can turn php objects or arrays into json with json_encode()

They will come out as an array or an object depending on whether you set the extra flag when decoding. json_decode($jsonstr,true) will return an array, json_decode($jsonstr) will return an object.

It doesn't matter whether the data was an object or an array before it went in, it only matters how you decode it.

Your code above will always return an array regardless of whether you encode an object or an array.

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.