从curl传递数据以在Codeigniter上查看

时间:2018-10-30 03:22:53

标签: php api codeigniter curl

我从curl中获取了一个json数据,然后我想将其发送到codeigniter中的视图,但是当我显示它时,会出现错误“非法字符串偏移”。 json数据:

{
"ProgramId": "29aee327-cd89-48c0-b79f-69a0e2b03709",
"ProgramName": "Microsoft CSP",
"CountryFullName": "Indonesia",
"CurrencyCode": "IDR",
"ProductGroups": [
    {
        "GroupName": "Microsoft 365",
        "Products": [
            {
                "ProductId": "3451a3b0-8cda-44a7-bad7-c30be81c4aaa",
                "ProductName": "Microsoft 365 F1",
                "ProductGroup": "Microsoft 365",
                "ProductSku": "3451A3B0-8CDA-44A7-BAD7-C30BE81C4AAA",
                "Price": 0,
                "MinQty": 1,
                "MaxQty": 10000000,
                "Qty": 0,
                "UnitPrice": 132300,
                "ProductUnit": "Licenses",
                "RetailPrice": 147000,
                "CommitmentValue": null,
                "TieredProductSku": null,
                "ProductType": "NON-SPECIFIC",
                "ProductDescription": "Designed to meet the needs of firstline workers in your organization. Offers best-in-class productivity across devices while providing IT with security  and control.",
                "ProductShortDescription": null,
                "ProductRestrictions": null,
                "IsTrialProduct": false,
                "BillingCycleDuration": 1
            }
        ],
        "IsExpanded": true,
        "Order": -10
    }

然后我从控制器中检索要发送到显示器的数据,这里我使用file_get_contents函数

public function index()
{
    $this->template->add_includes('js', 'assets/js/holder.js');
    $init = "";
    $this->template->add_init($init);

    // GET data 
    $source  = base_url().'api/products/'.$this->tenantId;
    $content = file_get_contents($source);
    $result  = json_decode($content, true);
    //print_r($result); exit;
    $data['products']=$result;

    $this->template->load('templates/Template', 'Demo',$data);
}

0 个答案:

没有答案