【问题标题】:syntax error in postman after json_encode()json_encode() 后邮递员中的语法错误
【发布时间】:2018-12-24 18:33:38
【问题描述】:

这是我的控制器

$pid = json_decode(file_get_contents('php://input'), true);
            foreach ($pid as $key => $value) {
                foreach ($value as $keys => $values) {
                    $c_res = $this->Model_master->get_sup($values);
                    echo json_encode($c_res, 200);
                } 
             } 

这是我的模特

                $q = $this->db->select('contact_number')->from('shopxie_people')
                                ->where("p_id = ".$value)
                                ->get();
                return $q->result_array();

这以 html 形式显示我的结果,但是当我将其更改为 json 时,它给了我

语法错误

在邮递员内容类型中也显示为 text/html;

为什么在我的代码中用 json 编码后还是会发生这种情况?

【问题讨论】:

  • “改成json”是什么意思?你能分享确切的错误信息吗?
  • 什么是200 in json_encode($c_res, 200) 删除它
  • @pradeep 仍然给出同样的错误
  • 不要让它进入 foreach 循环
  • @NicoHaase 我正在使用邮递员,所以我可以选择将输出更改为 html、json、xml、文本、自动

标签: php json codeigniter codeigniter-3


【解决方案1】:

希望对您有所帮助:

在你的控制器中做这样的事情:

foreach ($pid as $key => $value) 
{
   foreach ($value as $keys => $values) 
   {
      $c_res[] = $this->Model_master->get_sup($values);  
   }
}
echo json_encode($c_res);
exit;

【讨论】:

  • 快乐是我的,快乐的编码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-07
  • 2017-04-09
  • 2018-07-22
  • 1970-01-01
  • 2013-06-18
相关资源
最近更新 更多