-3

i am need preg_match this "supportsUnlock" : true,

code json

{
  "supportsUnlock" : true,
  "options" : [ "email", "questions" ],
  "account" : {
    "name" : "a@hotmail.com"
  },
  "emailAddress" : "a•••••@hotmail.com",
  "emailDomain" : "hotmail.com",
  "rescueEmail" : false,
  "forgotPasswordFlow" : true
}
ThamerPhp
  • 7
  • 1

2 Answers2

1

first store json in $json varibale

after decode it.

 $data = json_decode($json);

 print_r($data);

Check result after get it value by array.

Jydipsinh Parmar
  • 484
  • 5
  • 14
1

You can use json_decode() function for getting values from json.

Example:

<?php
$json = '{
  "supportsUnlock" : true,
  "options" : [ "email", "questions" ],
  "account" : {
    "name" : "a@hotmail.com"
  },
  "emailAddress" : "a•••••@hotmail.com",
  "emailDomain" : "hotmail.com",
  "rescueEmail" : false,
  "forgotPasswordFlow" : true
}';

$decodeJson = json_decode($json,true);
echo "<pre>";
print_r($decodeJson);
echo $decodeJson['supportsUnlock']; // true

?>

Result of print_r():

Array
(
    [supportsUnlock] => 1
    [options] => Array
        (
            [0] => email
            [1] => questions
        )

    [account] => Array
        (
            [name] => a@hotmail.com
        )

    [emailAddress] => a•••••@hotmail.com
    [emailDomain] => hotmail.com
    [rescueEmail] => 
    [forgotPasswordFlow] => 1
)

Also note that, json_decode(string,true) will return result in array format if you need result in object than you can just remove the second param of TRUE.

devpro
  • 16,184
  • 3
  • 27
  • 38