我需要preg_match这个 “supportsUnlock”:true,
代码json
{
"supportsUnlock" : true,
"options" : [ "email", "questions" ],
"account" : {
"name" : "a@hotmail.com"
},
"emailAddress" : "a•••••@hotmail.com",
"emailDomain" : "hotmail.com",
"rescueEmail" : false,
"forgotPasswordFlow" : true
}
答案 0 :(得分:1)
首先在$ json varibale中存储json
解码后。
$data = json_decode($json);
print_r($data);
按数组获取值后检查结果。
答案 1 :(得分:1)
您可以使用json_decode()
函数从json获取值。
示例:
<?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
?>
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
)
另请注意,json_decode(string,true)
如果您需要在对象中获得结果,则会以数组格式返回结果,而不是删除TRUE
的第二个参数。