首页 > 解决方案 > 将数据从 curl 传递到 codeigniter 上的视图

问题描述

我有一个来自 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);
}

标签: phpapicodeignitercurl

解决方案


推荐阅读