<?php
header('Content-Type: text/html; charset=UTF-8');
$json_string= [{"text":"test","created":"Sun Nov 08 01:07:10 +0000 2015","favorite_count":0,"retweet_count":0,"url":"","media_url":""}];
$obj=json_decode($json_string);
echo $obj->text;
?>如题,使用php解析json数据,使用下面代码出错:
<?php
header('Content-Type: text/html; charset=UTF-8');
$json_string= [{"text":"test","created":"Sun Nov 08 01:07:10 +0000 2015","favorite_count":0,"retweet_count":0,"url":"","media_url":""}];
$obj=json_decode($json_string);
echo $obj->text;
?>
你的如果是字符串, 应该加引号.
你输出的 text 属性是在 数组里(下标为0)的那个元素里.
或者是下面这样的:
因为不清楚你最初的数据是什么样的, 所以只能猜了.
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号