在Codeigniter中获取JSON响应 [英] Get JSON response In Codeigniter

查看:91
本文介绍了在Codeigniter中获取JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am passing the Object from fiddler to the service written in codeigniter. My Object is something look like this :

我的回复:

   {
   "GetResponse":{
      "OrgName":"adfasd",
      "OrgAdr1":"asdf",
      "OrgAdr2":"NA",
      "ProductList":[
          {
               "ProductID":8724,
               "Pallets":0,
               "Pieces":0,
               "Description":"sdfsd"
          }
       ]
   }
}

我想要的内容:

我想将响应另存为JSON对象,并希望在codeigniter中获取

I want to save the response as a JSON Object in codeigniter and also want to fetch the JSON Object or Array inside the main Object.

我尝试过的方法:

我在codeigniter中的服务方法如下:

My service method in codeigniter is something like this :

public function Save()
{
     $Data = json_decode(file_get_contents('php://input'));
     echo $Data;
}

但我的响应正文中没有任何内容提琴手。

But I am getting nothing in Response Body inside Fiddler.

如果我使用此代码:

$Data = file_get_contents('php://input');
echo $Data;

然后它以字符串形式显示响应。我想将其保存为JSON对象。

then it is showing me the response but in the form of String. I want to save it as an JSON Object.

有人可以告诉我我在这里缺少什么吗?

Can anyone tell me what am I missing here ?

推荐答案

使用以下代码:

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

$Data = json_decode(file_get_contents('php://input'),true);

现在,您将获得 $ Data 作为

,然后通过 $ Data ['name'] 获得价值。

这篇关于在Codeigniter中获取JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆