我想使用PHP将输入作为多个数组格式发送

时间:2017-11-26 03:23:43

标签: php

您好我的问题是我想要提供的请求是以下数组

["notes":{"email_id":"123","title":"John","notes":"15"},{"email_id":"15","title":"raj","notes":"hello"}],

但我的数组格式不同

{"email_id":"10","notes": ["hi,hello,how"],"title":"hello"}

喜欢这个请求只接受请帮帮我...... !!

<?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);
?>

上面是我的代码在上面的代码抄袭请求格式中作为多个数组,但我没有得到我在一个对象中有不同的发送请求 如何解决这个问题请使用原始数据作为邮递员请求发送 提前感谢你.. !!

2 个答案:

答案 0 :(得分:0)

如果问题是你在期待一个json对象时收到一个字符串,那么就这样做:

int value = 5;
NSMutableArray * anArray  = [[NSMutableArray alloc] init];
[anArray addObject: @(value)];

答案 1 :(得分:0)

您的json格式不正确

public class ApplicationUser : IdentityUser
{
   public string Name {get;set;}  //?? missing?

   public ICollection<UserTask> OwnedUserTasks { get; set; }
   public ICollection<UserTask> ExecutedUserTasks { get; set; }
}

正确的格式是

["notes":{"email_id":"123","title":"John","notes":"15"},{"email_id":"15","title":"raj","notes":"hello"}]

你可以使用json_decode()函数

在php中解码json

`