【问题标题】:codeigniter: how to get json date from api, send it to the view pagecodeigniter:如何从 api 获取 json 日期,发送到查看页面
【发布时间】:2014-08-13 09:21:10
【问题描述】:

我是 Codeigniter 的新手。我在这里寻求您的帮助..

如果我打开这个 url http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&random=1403540243 然后我会在我的浏览器上得到一些 json 日期,

如何调用相同的 url 并读取所有 json 日期将其发送到我在 Codeigniter 中的查看页面?

我试过这样,但是它发送的 url 没有读取这个 url 下的数据

public function getAllJsonData() {//first version
        $data['all_json_data'] = "http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&random=1403540243";
        $this->load->view('myViewPage', $data);
    }

【问题讨论】:

    标签: php json codeigniter


    【解决方案1】:
        public function getAllJsonData() {//first version
                $data['data'] = file_get_contents('http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&random=1403540243');
    //        $data['data'] = json_decode($data, true);
                $this->load->view('myViewPage', $data);
            }
    

    将以下代码粘贴到视图文件中

    <?php 
    header('Content-Type: application/json');
    echo $data; 
    ?>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多