无法在本地主机上检索JSON对象 [英] cant retrieve JSON object on localhost
本文介绍了无法在本地主机上检索JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在本地主机上检索JSON对象,问题是它不会输出任何内容. JSON对象可能如下所示:
I'm trying to retrieve JSON Objects on my localhost, the issue is that it wont output anything. The JSON objects could look like following:
[
{
NAME: "Hearthstone",
PLAYER1: "Rdu ",
PLAYER2: "Savjz ",
status: 2,
meta: "LIVE"
},
{
NAME: "League of Legends",
PLAYER1: "Team King ",
PLAYER2: "EDG ",
status: 2,
meta: "28.12."
}]
php检索对象.
$url = "http://localhost:8888/crawl_JSON.php";
$json = file_get_contents($url);
$json_output = json_decode($json);
echo $json_output;
为什么不输出任何东西?
Why don't it output anything?
推荐答案
请注意,json_decode()
返回一个对象,您不能echo
您需要使用var_dump
或print_r
.如果您想回显,则可以回显JSON字符串.
Note that json_decode()
returns an object, you cannot echo
you will need to use var_dump
or print_r
. If you want to echo , you can echo the JSON string.
$url = "http://localhost:8888/crawl_JSON.php";
$json = file_get_contents($url);
echo $json;
$json_output = json_decode($json);
var_dump($json_output);
在 crawl_JSON.php 内,您需要echo
JSON
,需要确保它有效.
And inside of crawl_JSON.php You need to echo
the JSON
, you will need to make sure it is valid.
<?php
echo '
[
{
"NAME": "Hearthstone",
"PLAYER1": "Rdu ",
"PLAYER2": "Savjz ",
"status": 2,
"meta": "LIVE"
},
{
"NAME": "LeagueofLegends",
"PLAYER1": "TeamKing",
"PLAYER2": "EDG",
"status": 2,
"meta": "28.12."
}
]
';
这篇关于无法在本地主机上检索JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文