java - 如何使用Codeigniter 3从java网站获取Json数据?

标签 java php json httpclient codeigniter-3

我将选择从第三方网站返回值的数据,如下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"
}

最佳答案

请尝试下面的代码

$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” key 或访问 $content_arr['LuckDrawProductList][0]

关于java - 如何使用Codeigniter 3从java网站获取Json数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33344193/

相关文章:

java - 我会在这里同步什么?

java - 如何使用 JAVA GUI 在数据库 MySQL 中乘以 2 列?

javascript - CSS calc如何根据一定的li的量来使用?

python - 将 Python 的字典列表转换为 Postgresql 的 json 数组

javascript - HighCharts 柱形图到饼图

java - Spring Data JPA 规范继承 `criterialBuilder.treat` 不起作用

java - 将第一个文件的每一行与java中第二个文件的全部内容进行比较

php - mysql_query 到 PDO 和准备好的语句

php - onclick 添加 1 到计数器 + 存储到服务器

asp.net - JSON 调用 + .net 在内置 Web 服务器上以 Debug模式工作,但不能直接转到虚拟目录