php - 如何在 CodeIgniter 控制器中读取 JSON 文件
问题描述
我无法在 codeigniter 控制器中读取我的 json 文件,它返回错误。
我的代码:
$curYear = date("Y");
$string = file_get_contents(base_url("assets/data/".$curYear."_cal.json"));
我的控制器尝试使用以下命令读取 json 文件返回错误消息:
file_get_contents(//localhost/EBR_Labeling/assets/data/2018_cal.json):无法打开流:没有这样的文件或目录
解决了
使用此语法:
file_get_contents("./assets/data/".$curYear."_cal.json")
解决方案
请使用此代码-
<?php
$json = file_get_contents(FILE_PATH);
$obj = json_decode($json);
echo '<pre>' . print_r($obj) . '</pre>';
?>
如果您需要任何其他帮助,请告诉我。
谢谢
推荐阅读
- rest - Google Calendar v3 api 何时会在获取事件响应中包含参加者 displayName?
- bigdata - 我们可以在 Kusto 中以年为单位设置表的保留期吗?
- javascript - nodejs从foreach循环中读取数据
- nlp - Spacy模式匹配规则形成
- android - 忽略 android.intent.action.SEND 上的 FLAG_ACTIVITY_CLEAR_TASK
- r - R,将 tbl_regression 与 glmer 一起使用时,获取错误消息“x”必须是至少二维的数组
- windows - Windows 的视频映射驱动程序
- node.js - 如果第一种失败,则选择第二种响应方式
- slack - 有没有办法将人们标记为 slack slash 命令
- python - 使用另一个数组重新排序和切片 numpy 数组