php如何获取json⾥的值,如何从JSONPHP正确获取值?要从JSON获取值,请使⽤json_decode()。假设以下是我们的JSON$detailsJsonObject = '{"details": [{"name":"John","subjectDetails":{"subjectId":"101","subjectName":"PHP","marks":"58", "teacherName":"Bob"}}]}';
我们需要获取特定的值,例如主题名称,标记等。
⽰例
PHP代码如下html>
$detailsJsonObject = '{"details":[
{"name":"John","subjectDetails":
{"subjectId":"101","subjectName":"PHP","marks":"58",
"teacherName":"Bob"}
}]}';
$convertToArrayObject = json_decode($detailsJsonObject,true);
$actualSubjectName = $convertToArrayObject[details][0][subjectDetails][subjectName];
phpjson格式化输出$actualTeacherName = $convertToArrayObject[details][0][subjectDetails][teacherName];
echo "The Subject Name is=",$actualSubjectName,"
";
echo "The Teacher Name is=",$actualTeacherName;
>
输出结果
这将产⽣以下输出The Subject Name is=PHP
The Teacher Name is=Bob
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论