[英]i want to send input as multiple array formats using php
Hi my question is i want giving like request is the below arrays 嗨,我的问题是我想给像请求是下面的数组
["notes":{"email_id":"123","title":"John","notes":"15"},{"email_id":"15","title":"raj","notes":"hello"}],
but i got array format as different 但是我得到了不同的数组格式
{"email_id":"10","notes": ["hi,hello,how"],"title":"hello"}
like this request only accepted please help me out...!! 像这样的请求只接受,请帮帮我...!
<?php
include('db.php');
$input = file_get_contents('php://input');
$input = json_decode($input);
$json=array();
$email= $input->email_id;
$title = $input->title;
$notes= $input->notes;
$noteid= $input->note_id;
//echo json_encode($email);
if($email != '')
{
foreach($email as $key=>$value){
if($noteid == '')
$qry= mysqli_query($conn,"INSERT INTO `notes`( `email_id`, `title`, `notes`) VALUES ('$value','$title[$key]','$notes[$key]')");
else
$qry= mysqli_query($conn,"update `notes` set `email_id` = '$value', `title` = '$title[$key]', `notes` = '$notes[$key]' where id = '$noteid' ");
}
if($qry){
$json = array("response" => "success", "status"=>1 ,"msg" => (($noteid == '') ? "insert ": "Update ")."done!");
}
else{
$json = array("response" => "failed", "status"=>0 ,"msg" => (($noteid == '') ? "insert ": "Update ")."failed!");
}
}
else
$json = array("response" => "failed", "status"=>2 ,"msg" => "Request Not Reached!");
echo json_encode($json);
?>
above is my code in the above code sneding request format as multiple arrays but i am not getting i got different sending request in one object how to solve this please find it using as raw data sending as postman request thanking you in advance..!! 上面是我在以上代码发送请求格式中作为多个数组的代码,但我没有得到一个对象有不同的发送请求,如何解决此问题,请使用原始数据作为邮递员发送请求找到它,谢谢。
If the problem is that you are receiving a string when you're expecting a json object then just do this: 如果问题是您在期望json对象时收到字符串,则只需执行以下操作:
header('Content-Type: application/json');
echo json_encode($json);
Your json format is no correct 您的json格式不正确
["notes":{"email_id":"123","title":"John","notes":"15"},{"email_id":"15","title":"raj","notes":"hello"}]
Correct format is 正确的格式是
{"notes":[{"email_id":"123","title":"John","notes":"15"},{"email_id":"15","title":"raj","notes":"hello"}]}
than you can json decode in php using json_decode() function 比你可以使用json_decode()函数在php中进行json解码
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.