$result = $DB-selectgoods gid money name note name~ = $name LIMIT = $offset $limit;php把数据库查出的这个字符串note例如cid1882yid1变json返回怎么写
可以使用PHP内置的json_decode()函数将字符串转换为JSON格式数据,例如:
// 假设 $row 是从数据库中查出的一条数据 $row = [ 'gid' => 1, 'money' => 100, 'name' => 'iPhone', 'note' => '{"cid":"1882","yid":"1"}' ]; // 将字符串转换为JSON格式数据 $row['note'] = json_decode($row['note'], true); // 输出转换后的数据 print_r($row);
输出结果如下:
Array ( [gid] => 1 [money] => 100 [name] => iPhone [note] => Array ( [cid] => 1882 [yid] => 1 )
)
其中,json_decode()函数第二个参数设为true,表示将JSON格式数据转换为关联数组。如果不设置该参数,则默认转换为对象。
原文地址: https://www.cveoy.top/t/topic/bdxE 著作权归作者所有。请勿转载和采集!