拥有以下字符串:
"[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]"
如何从1
部分获取required
?我只需要1
。
提前致谢。
答案 0 :(得分:3)
假设字符串始终为JSON,请使用json_decode()
:
$array = json_decode('[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]');
现在您可以按如下方式访问required
选项:
$array[0]->required;
答案 1 :(得分:0)
您可以使用json_decode:
<?php
$string = '[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]';
$string_array = json_decode($string, true);
echo $string_array[0]['required'];
?>
答案 2 :(得分:0)
使用函数json_decode和current:
在单行中$str = '[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]';
$required = current(json_decode($str))->required;