我在弄清楚如何从 MySQL 查询中获取 JSON 结果时遇到了一些麻烦;把它们变成一个 PHP 数组;从该数组中删除相同的字段,然后将数组转回 JSON。[1] 是包含实际 JSON 的行的一部分。
我错过了什么吗?无法在网站上找到任何类似的问题。谢谢!
$data = mysql_fetch_row($result);
print_r($data);
$json = json_decode($data[1], TRUE);
var_dump($json);
print_r($json);
$distinctresult = array_unique($json);
print_r($distinctresult);
$final = json_encode($distinctresult);
{"rows":[{"level":"ERROR","key":"Standard Not found","value":"RI.1.8"},{"level":"ERROR","key":"Standard Not found",{"level":"ERROR","key":"Standard Not found","value":"RI.K.9"},{"level":"ERROR","key":"Standard Not found","value":"RI.K.9"},{"level":"ERROR","key":"Standard Not found","value":"RI.K.9",}]}
这是我正在使用的 MySQL 查询:
"select distinct d.valueField
from etllogs t
inner join etllogdetails d on t.uid = d.etllogID and d.valueField like '%ERROR%'
where t.transformationName like 'CM Data Extract'
and (t.timestamp >= (now() - interval 24 hour))
order by t.timestamp desc;";