我已尝试打印json response
但""
已添加到我的json response
我尝试了php
id
和drupal field
<?php
$data = array("title"=>"test","body"=>"test body");
$php = json_encode($data,JSON_FORCE_OBJECT);
echo json_encode(array("php"=>$php,"id"=>10));
?>
输出
{"php":"{\"title\":\"test\",\"body\":\"test body\"}","id":10}
但我想要输出如下
{"php":{"title":"test","body":"test body"},"id":10}
我为上述问题添加了更多代码
{"php":"{\"title\":\"test\",\"body\":\"test body\"}","id":10}
为什么不从json_encode
echo json_encode($php);
我如何第二次获得高于输出
答案 0 :(得分:3)
您使用JSON编码两次:
$data = array("title"=>"test","body"=>"test body");
$php = json_encode($data,JSON_FORCE_OBJECT);
echo $php ; // remove json_encode() here
问题编辑后:
$data = array("title"=>"test","body"=>"test body");
echo json_encode(array("php"=>$data,"id"=>10));
答案 1 :(得分:0)
您也可以这样做,
<?php
$data = array("title"=>"test","body"=>"test body");
echo json_encode(array("php"=>$data,"id"=>10));
?>