我需要创建数据如下:
{v: 1.0, f: '<h1>1.0</h1>'}
...
但现在我只知道如何获取第一个参数,所以我得到:{v: 1.0}
,
使用此代码:
$temp[] = array('v' => (string) $naziv);
我需要添加到我的代码中:$temp[] = array('v' => (string) $naziv);
得到这样的json:{v: 1.0, f: '<h1>1.0</h1>'}
最佳答案
$naziv = 1.0;
$header ='<h1>1.0</h1>';
$temp[] = array('v' => (string) $naziv,
'f' => (string) $header
);
echo json_encode($temp);
或
$naziv = 1.0;
$header ='<h1>1.0</h1>';
$temp['v'] = $naziv;
$temp['f'] = $header;
echo json_encode($temp);
关于javascript - 创建特定格式的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24064153/