0

I've got this object. This is the var_dump of my object:

object(stdClass)#2 (3) {
  ["status"]=>
  bool(true)
  ["sql"]=>
  string(122) "SELECT * FROM `story`"
  ["story"]=>
  array(12) {
    ["id"]=>
    string(1) "1"
    ["user_id"]=>
    string(1) "1"
    ["gb_id"]=>
    string(12) "tYQz0zq5-DQC"
    ["date"]=>
    string(19) "0000-00-00 00:00:00"
    ["title"]=>
    string(14) "1893.21.04-148"
    ["story"]=>
    string(4026) "<TEXTFORMAT LEADING="2"><P>HTML STUFF</P></TEXTFORMAT>"
    ["image"]=>
    NULL
    ["views"]=>
    string(1) "1"
    ["username"]=>
    string(9) "username"
    ["password"]=>
    string(6) "789456"
    ["email"]=>
    string(7) "email"
    ["story_id"]=>
    string(1) "3"
  }
}

But when I try to json_encode it, it returns nothing. Does anyone have an idea why?

Has it anything to do with the fact that it could be to big? (Because a left out some big chunks of data above )

JAAulde
  • 19,250
  • 5
  • 52
  • 63
GenericUser
  • 221
  • 3
  • 19
  • stdClass is probably not encodable. Where is this coming from? If it's the return value of a json_decode, pass `true` as the second parameter to get an array instead of an object. – Maerlyn Aug 15 '14 at 13:52
  • `json_encode` cannot return `NULL`, it can only return a `string` or boolean `FALSE`. If it returns `FALSE` there was an error. – Sean Bright Aug 15 '14 at 13:53
  • 6
    After you call to `json_encode`, make a call to `json_last_error` and check its return value here: http://php.net/manual/en/function.json-last-error.php – JAAulde Aug 15 '14 at 13:54
  • It *returns* nothing? Or you just haven't prefaced it with an `echo` statement, and therefore aren't getting any output? – esqew Aug 15 '14 at 13:54
  • You got some non-utf values on the part that you didn't posted ? It can be the problem. See http://stackoverflow.com/questions/3180690/php-json-encode-returning-null, and http://stackoverflow.com/questions/1972006/json-encode-is-returning-null – hlscalon Aug 15 '14 at 13:55
  • Can you provide a `var_export`? – ʰᵈˑ Aug 15 '14 at 14:02
  • 1
    An stdClass is encodebale. The problem is utf-8 formatting. Thanks guys! – GenericUser Aug 15 '14 at 14:05
  • @Maerlyn There's nothing wrong with `json_encode`ing the `stdClass`. Quick example: http://3v4l.org/hqnLe – Patrick Q Aug 15 '14 at 14:06

0 Answers0