我需要像这样创建数据:
{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>'}
答案 0 :(得分:2)
$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);
答案 1 :(得分:1)
<?php
$naziv = 1.0;
$temp = array(
"v" => $naziv
"f" => "<h1>{$naziv}</h1>",
);
echo json_encode($temp);
这将导致
{"v":1.0,"f":"<h1>1.0</h1>"}