在Codeigniter中获取JSON响应

Jig*_*Raj 3 php json codeigniter

我将对象从提琴手传递给用codeigniter编写的服务.我的对象看起来像这样:

我的回复 :

   {
   "GetResponse":{
      "OrgName":"adfasd",
      "OrgAdr1":"asdf",
      "OrgAdr2":"NA",
      "ProductList":[
          {
               "ProductID":8724,
               "Pallets":0,
               "Pieces":0,
               "Description":"sdfsd"
          }
       ]
   }
}
Run Code Online (Sandbox Code Playgroud)

我想要的是 :

我想将响应保存为codeigniter中的JSON对象,并且还想在主Object中获取JSON对象或数组.

我尝试了什么:

我在codeigniter中的服务方法是这样的:

public function Save()
{
     $Data = json_decode(file_get_contents('php://input'));
     echo $Data;
}
Run Code Online (Sandbox Code Playgroud)

但是我在Fiddler里面的Response Body里什么都没得到.

如果我使用此代码:

$Data = file_get_contents('php://input');
echo $Data;
Run Code Online (Sandbox Code Playgroud)

然后它以String的形式向我显示响应.我想将其保存为JSON对象.

谁能告诉我,我在这里失踪了什么?

Kva*_*tar 9

使用此代码:

header('Content-type: application/json');

$Data = json_decode(file_get_contents('php://input'),true);
Run Code Online (Sandbox Code Playgroud)

现在,你将得到$Data一个数组.

你得到的价值$Data['name'].