在php中回显JSON数据

问题描述:

我正在尝试回显一些JSON数据.问题是数据包含变量,但是我的代码没有将变量放入字符串中. 这是我的代码:

Im trying to echo some JSON Data. The problem is the data contains variables but my code isn't putting the variables into the string. Heres my code:

$status = $row['Status'];
$priority = $row['Priority'];
echo '{"status":"$status","priority":"$priority"}' ; 

此php回显

{"status":"$status","priority":"$priority"}

当我需要回声

{"status":"Completed","priority":"High"}

例如.我该如何解决?

只需使用 json_encode 函数

echo json_encode($row);