简体   繁体   English

Json数据显示-CSS,HTML

[英]Json data display - css, html

Welcome! 欢迎! I have a question. 我有个问题。 Today i tried to get json api from URL and i have this code: 今天,我试图从URL获取json api,我有以下代码:

 <?php
$url = "http://services.faa.gov/airport/status/LAX?format=json";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);
$json = curl_exec($ch);
if(!$json) {
    echo curl_error($ch);
}
curl_close($ch);
print_r(json_decode($json));
?>

In return in html i have something like this: 作为回报,我有这样的东西:

 stdClass Object ( [delay] => false [IATA] => LAX [state] => California [name] => Los Angeles International [weather] => stdClass Object ( [visibility] => 10 [weather] => Overcast [meta] => stdClass Object ( [credit] => NOAA's National Weather Service [updated] => 9:53 PM Local [url] => http://weather.gov/ ) [temp] => 54.0 F (12.2 C) [wind] => East at 12.7mph ) [ICAO] => KLAX [city] => Los Angeles [status] => stdClass Object ( [reason] => No known delays for this airport. [closureBegin] => [endTime] => [minDelay] => [avgDelay] => [maxDelay] => [closureEnd] => [trend] => [type] => ) )

And now my question is how to style it in css and display it nice not in this way like above 现在我的问题是如何在css中设置样式并显示它,而不是像上面那样

When you use: 使用时:

$obj = json_decode($json);

It will return std class object, you can access its values like: 它将返回std类对象,您可以访问其值,例如:

$obj->name;
$obj->delay;

and so on. 等等。 Now you can use your own html & css to display it nice 现在您可以使用自己的html&css来显示它了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM