无法合并2个JSON结果并从PHP脚本获取响应
我试图从select语句中获取一个结果,我使用了两条语句,并希望得到两个输出的JDON响应。就这些 问题:我正在测试Chrome Postman,它正在显示结果无法合并2个JSON结果并从PHP脚本获取响应,php,json,Php,Json,我试图从select语句中获取一个结果,我使用了两条语句,并希望得到两个输出的JDON响应。就这些 问题:我正在测试Chrome Postman,它正在显示结果 [ null, null ] 下面是我的php代码;我哪里做错了 <?php header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); header('Acce
[
null,
null
]
下面是我的php代码;我哪里做错了
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,x-prototype-version,x-requested-with');
header('Cache-Control: max-age=900');
header("Content-Type: application/json"); // tell client that we are sending json data
define("DB_USR","erSKJV");
define("DB_PsAS","T");
define("DB","ipaddress/orcl.profits");
$conn = oci_connect(DB_USR,DB_PAS,DB);
if (!$conn)
{
$e = oci_error();
$result["message"] = $e['message'];
echo json_encode($result);
exit(1);
}
$loggedinuser = $_POST['loggedinuser'];
$stmt = "select count(*) as taskgiven from admtask where CLOSE_DT is null and primary='".$loggedinuser."' ";
$stmt1 = "select count(*) as mytask from admtask where CLOSE_DT is null and entusr='".$loggedinuser."' ";
$result=oci_parse($conn,$stmt);
$ex2=oci_execute($result);
while ($row=oci_fetch_assoc($result))
{
$stmta[] = $row;
}
json_encode($stmta);
$result1=oci_parse($conn,$stmt1);
$ex2=oci_execute($result1);
while ($row1=oci_fetch_assoc($result1))
{
$stmtb[] = $row1;
}
json_encode($stmtb);
$final[] = json_decode($stmta,true);
$final[] = json_decode($stmtb,true);
$json_merge = json_encode($final);
echo json_encode($json_merge);
?>
json\u encode返回json的字符串。您需要在前两次编码期间将其分配给变量
while ($row=oci_fetch_assoc($result))
{
$stmta[] = $row;
}
$stmta = json_encode($stmta);
$result1=oci_parse($conn,$stmt1);
$ex2=oci_execute($result1);
while ($row1=oci_fetch_assoc($result1))
{
$stmtb[] = $row1;
}
$stmtb = json_encode($stmtb);
您不应该在包含json的数组上调用json\u encode()
。将原始数组放入容器数组中,然后对整个对象调用json\u encode()
$final = array($stmta, $stmtb);
echo json_encode($final);
检查$stmta和$stmtb在ijson_编码($stmta)时返回什么
然后显示使用此代码的结果,但它在json数据之间提供斜杠。如何删除这些斜杠。请发布您的结果“[[\“任务\”:\“25\”}],“{\“我的任务\”:\“80\”}]”仍然有问题,请尝试相同的方法,尽快让您知道结果