2

I have the following values inside curly braces.

{ "address": "test@test.com", "did_you_mean": null, "is_valid": true, "parts": { "display_name": null, "domain": "test.com", "local_part": "test" }}

I need to get the value of "is_valid". I tried json_decode to get the value. But it didn't help me to find the result. Anyone please help me to find a solution.

Nithinkumar CN
  • 287
  • 1
  • 5
  • 18
  • Possible duplicate of [How do I extract data from JSON with PHP?](http://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – user3942918 Mar 29 '17 at 08:08
  • Post tried code!! – Saty Mar 29 '17 at 08:08
  • You either can do `$object =json_decode($string)`which returns an object, or `$array = json_decode$string, true)` which returns an array. This way, you can do`$object->is_valid` for the first example, or `$array['is_valid']`for the second one – Amitsouko Mar 29 '17 at 08:13

1 Answers1

4

Why json_decode didn't work ? I tested it with that code and works perfectly:

$str= '{ "address": "test@test.com", "did_you_mean": null, "is_valid": true, "parts": { "display_name": null, "domain": "test.com", "local_part": "test" }}';
$obj = json_decode($str);

echo $obj->is_valid;
VirCom
  • 3,414
  • 1
  • 10
  • 10