如何获取 json 格式的字符串格式的数字?

How to get the number in string format for json format?

我编写此代码以将 google 图表输出为 json 格式。但是,数字的 return 值变为字符串,google 图表无法读取。

$rows = array();
foreach($data as $item) {
$a = new stdClass;
$a->v = $item->location_name;
$a->f = null;

$b = new stdClass;
$b->v = $item->count;
$b->f = null;

$c = new stdClass;
$c->c = array($a, $b);

$rows[] = $c;

}
$cols1 = new stdClass;
$cols1->id = '';
$cols1->label = 'STATE';
$cols1->pattern = '';
$cols1->type = "string";

$cols2 = new stdClass;
$cols2->id = '';
$cols2->label = 'TOTAL';
$cols2->pattern = '';
$cols2->type = "number";

$returndata = new stdClass;
$returndata->cols = array($cols1, $cols2);
$returndata->rows = $rows;

echo json_encode($returndata);

输出变成这样:

查询是这样的:

$sql = "Select ljl.location_id, count(ljj.job_id) as count, ljl.location_name from {local_jobs_job} ljj inner join {local_jobs_location} ljl on ljj.job_location = ljl.location_id group by ljl.location_name";

您可以将已知的 "string-number" 列转换为数字,例如 $b->v = intval($item->count);(int) $item->count