相关文章推荐
任性的镜子  ·  redis lua定时器 ...·  1 年前    · 
一身肌肉的遥控器  ·  BI PUBLISHER ...·  1 年前    · 
无聊的葡萄酒  ·  Excel VBA find ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a response coming back that is JSON encoded, but when I decode it I lose the true / false attributes after using $var = json_decode($response); .

Here’s an example:

"domain": "my.domain.com", "created_at": "2014-11-15 00:26:53.74059", "valid_mx": true

I’ve even tried:

$var = json_decode($response, true);

But it still seems to drop the true/false. How can I properly pull the true/false from the response? What am I missing?

doesn't matter, just trying to validate based on the valid_mx response. Either way it seems to drop the true/false – MrTechie Jan 16, 2015 at 18:32

Your problem is with print_r, not json_decode.

print_r does not show true / false for true / false. Instead, it shows 1 / (blank).

You can use var_dump($var); or var_export($var); instead which will show you the correct values.

That works - I was trying to pull out the actual 'true/false' response but didn't think to actually check to see if it was set. Thanks – MrTechie Jan 16, 2015 at 18:39 @Rizier123 Sure, but I wasn't questioning your answer. I was just clarifying that the value is set either way, in response to MrTechie's comment. Sorry for the confusion. – showdev Jan 16, 2015 at 18:52 "true" does not have anything to do with JSON booleans, it's just an arbitrary text that you, as human, may decide to arbitrarily map as logical value, just as you could do with "on", "yes", "OK" or "Verdadero". – Álvaro González Mar 21 at 10:15 As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Mar 26 at 12:05

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.