php - 将数据从 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);
}
解决方案
推荐阅读
- c# - 为什么我的代码没有对此 if 语句做出反应(全局变量)
- android - 我的对话框中未触发 webviews onclicklistener
- composer-php - 如何解决安装 Avalara 的“您的要求无法解析为一组可安装的软件包”?
- python-3.x - 遍历列表或在 python 中设置
- magento - 学习 Magento 主题开发的最佳方式是什么?
- python - 运行 Python 代码时如何从 Pylint 获取报告 + 分数?
- scala - ScalikeJDBC 结果字符串中的列顺序错误
- tcl - 是否有 Tcl 包初始化程序?
- r - 根据前一个变量是否在向量中创建一个新的二进制变量 (R)
- ruby - 如何查找所有没有数组或小于数组的文档