【问题标题】:How to get Json data from java website by using Codeigniter3?如何使用 Codeigniter3 从 Java 网站获取 Json 数据?
【发布时间】:2015-10-26 11:06:35
【问题描述】:

我将选择从第三方网站返回值的数据,格式如下 Json 对象,并且该网站使用 Java 语言和 tomcat 数据库构建。

问题如何从该网站获取包含?

服务器说明

网址http://103.5.126.24/PalmHallServer/coodraw/coodraw!queryAllProduct.action

返回数据 json对象,所有产品信息数组的luckDrawProductList,

{
    "LuckDrawProductList": [
        {
            "BaseTime": 20140119133000,
            "CommissionRatio": 10,
            "DeductBetCount": 1,
            "Detail": "You can enter any amount between ...",
            "Enable": 1,
            "FreeResDiscount": 1,
            "LotteryTime": 20151016164500,
            "LuckDrawDesc": "DRAW1",
            "LuckDrawDiscount": 1,
            "MaxLuckNumLen": 5,
            "MaxMoney": 2000000,
            "MinLuckNumLen": 5,
            "MinMoney": 100,
            "NextStartTime": "2015-10-16 12:00:00",
            "NextStopTime": "2015-10-16 16:15:00",
            "OpenDrawType": -1,
            "PeriodUnit": 1,
            "PeriodUnitNum": 1,
            "Price": 40,
            "ProductCode": "DRAW1",
            "ProductDesc": "Draw1",
            "ProductEndTime": 20990119163000,
            "ProductId": 11111,
            "ProductType": 11,
            "Rate": 0,
            "ResTmplProductId": 11111,
            "StopTime": 1800,
            "ValidPeriod": 2
        }
    ],
    "Period": "201510161645"
}

【问题讨论】:

  • 你在使用 Gson 吗? @Cambodia_channel
  • 我想在 PHP 中使用 httpClient,因为我的团队合作让我不得不使用它

标签: java php json httpclient codeigniter-3


【解决方案1】:

请尝试下面的代码

$URL = "http://103.5.126.24/PalmHallServer/coodraw/coodraw!queryAllProduct.action";

$content = file_get_contents($URL);    // get json data using file_get_content
$content_arr = json_decode($content); // json data to php array.

或者如果你想使用 curl

$s = curl_init(); 
curl_setopt($s,CURLOPT_URL,$this->_url);
curl_setopt($s,CURLOPT_RETURNTRANSFER,true);    
$result = curl_exec($s);
curl_close($s);
$content_arr = json_decode($result); // json data to php array.

然后您可以 print_r($content_arr) 并检查“LuckDrawProductList”密钥或访问 $content_arr['LuckDrawProductList][0]

【讨论】:

  • 我收到错误致命错误:在第 83 行调用 D:\My data\project\wamp\www\lottery\application\views\templates\content.php 中未定义的函数 file_get_content() 跨度>
  • 欢迎并为 file_get_content 感到抱歉,我已将其更改为 file_get_contents
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 2011-01-03
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 2021-02-14
相关资源
最近更新 更多