我正在尝试如下解码JSON字符串-
<?php
$data = '{"hrm.com": { "a": "1", "b": "c" }}';
$character = json_decode($data);
$character = json_decode($character->hrm.com);
echo $character->a;
?>
我遇到了错误
Undefined property: stdClass::$hrm
有帮助吗?
答案 0 :(得分:3)
一个json_decode
就足够了:
$character = json_decode($data);
echo $character->{'hrm.com'}->a;
或者您可以使用json_decode
函数的第二个参数来返回关联数组:
$character = json_decode($data, true);
echo $character['hrm.com']['a'];
答案 1 :(得分:1)
尝试一下-
<?php
$data = '{"hrm.com": { "a": "1", "b": "c" }}';
$character = json_decode($data,true);
echo $character['hrm.com']['a'];
?>