通过PHP从URL读取JSON值 [英] Read JSON values from URL via PHP

查看:555
本文介绍了通过PHP从URL读取JSON值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用此简单JSON {"result":true,"data":[{"Position":"135"}]}

i have url with this simple JSON {"result":true,"data":[{"Position":"135"}]}

我试图以此来阅读它:

$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->result[1]->data->Position;

但不起作用.我在哪里弄错了?感谢您的帮助!

but it not works. Where i do a mistake? Thanks for helping!

推荐答案

您错误地处理了从JSON字符串创建的PHP对象中的数据

You are incorrectly addressing the data in the PHP object created from the JSON String

$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->data[0]->Position;

或者如果发生更多次

foreach ( $obj->data as $idx=>$data) {
    echo $data->Position;
}

这篇关于通过PHP从URL读取JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆