0

I have an object like this:

[
[
    "checkthisout.net",
    "1524621",
    "1",
    "Amazing Wines",
    "",
    "0",
    "",
    " ",
    " ",
    "hash",
    {
        "i": "http://img.chekthisout.net/xyz.jpg",
        "l": "//link_to_checkthisout.net",
        "adc": []
    }
],
[
    "allthebuzz.com",
    "1482859",
    "1",
    "Best Retirement Communities in USA",
    "",
    "0",
    "",
    " ",
    " ",
    "hash",
    {
        "i": "http://img.allthbuzz.com/abc.jpg",
        "l": "//link_to_allthebuzz.com",
        "adc": []
    }
],
]

When I use json_decode() on this, I get an array as expected. However, the curly braces content is parsed as "stdClass" (as reported by the debugger). I am not sure how to access this data within my code?

hvs
  • 518
  • 1
  • 5
  • 21
  • You may want pass `true` as second argument of `json_decode`: [doc](http://php.net/manual/en/function.json-decode.php) – Federkun Oct 17 '15 at 17:31

2 Answers2

3

You have to pass a second arg of true value to json_decode(), if you want to get the result as array

json_decode($json, true);

If you don't pass true for the second arg, you'll get stdClass like

object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
}
samayo
  • 16,163
  • 12
  • 91
  • 106
3

Pass true as the second parameter of json_decode().

That way it will return an associative array instead of an object.

Or you could use get_object_vars() to get data from the object.