php html 解析json,如何使用PHP将JSON解析为html表?

小编典典

从外部来源获取数据时,要做的第一件事就是了解所返回的内容。

也是

$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");

$data = json_decode($json);

print_r($data);

结果:

stdClass Object

(

[stand] => Array

(

[0] => stdClass Object

(

[afko] => Risne Stars HS 1

[ID] => 2091

[status] => Actief

[gespeeld] => 3

[percentage] => 100.0

[punten] => 6

[tegenscore] => 149

[eigenscore] => 191

[datum] => 2014-10-05

[saldo] => 42

[team] => Risne Stars Heren 1

[positie] => 1

)

[1] => stdClass Object

(

[afko] => D.B.V. Arriba HS 2

[ID] => 1813

[status] => Actief

[gespeeld] => 2

[percentage] => 0.0

[punten] => 0

[tegenscore] => 116

[eigenscore] => 102

[datum] => 2014-10-05

[saldo] => -14

[team] => D.B.V. Arriba Heren 2

[positie] => 10

)

[2] => stdClass Object

(

[afko] => The Valley Bucketeers HS 2

[ID] => 2430

[status] => Actief

[gespeeld] => 2

[percentage] => 0.0

[punten] => 0

[tegenscore] => 177

[eigenscore] => 70

[datum] => 2014-10-05

[saldo] => -107

[team] => The Valley Bucketeers Heren 2

[positie] => 11

)

[3] => stdClass Object

(

[afko] => Uitsmijters HS 2

[ID] => 2143

[status] => Actief

[gespeeld] => 2

[percentage] => 100.0

[punten] => 4

[tegenscore] => 79

[eigenscore] => 161

[datum] => 2014-10-05

[saldo] => 82

[team] => Uitsmijters Heren 2

[positie] => 2

)

[4] => stdClass Object

(

[afko] => Picker Reds HS 1

[ID] => 2056

[status] => Actief

[gespeeld] => 3

[percentage] => 66.7

[punten] => 4

[tegenscore] => 193

[eigenscore] => 184

[datum] => 2014-10-05

[saldo] => -9

[team] => Picker Reds Heren 1

[positie] => 3

)

[5] => stdClass Object

(

[afko] => Peatminers HS 2

[ID] => 6247

[status] => Actief

[gespeeld] => 1

[percentage] => 100.0

[punten] => 2

[tegenscore] => 36

[eigenscore] => 64

[datum] => 2014-10-05

[saldo] => 28

[team] => Peatminers Heren 2

[positie] => 4

)

[6] => stdClass Object

(

[afko] => Jolly Jumpers HS 1

[ID] => 1994

[status] => Actief

[gespeeld] => 2

[percentage] => 50.0

[punten] => 2

[tegenscore] => 103

[eigenscore] => 119

[datum] => 2014-10-05

[saldo] => 16

[team] => Jolly Jumpers Heren 1

[positie] => 5

)

[7] => stdClass Object

(

[afko] => TONEGO '65 HS 2

[ID] => 2120

[status] => Actief

[gespeeld] => 2

[percentage] => 50.0

[punten] => 2

[tegenscore] => 107

[eigenscore] => 122

[datum] => 2014-10-05

[saldo] => 15

[team] => TONEGO '65 Heren 2

[positie] => 6

)

[8] => stdClass Object

(

[afko] => Amical HS 2

[ID] => 1791

[status] => Actief

[gespeeld] => 3

[percentage] => 33.3

[punten] => 2

[tegenscore] => 180

[eigenscore] => 195

[datum] => 2014-10-05

[saldo] => 15

[team] => Amical Heren 2

[positie] => 7

)

[9] => stdClass Object

(

[afko] => S.V.Z.W. HS 2

[ID] => 5526

[status] => Actief

[gespeeld] => 3

[percentage] => 33.3

[punten] => 2

[tegenscore] => 174

[eigenscore] => 151

[datum] => 2014-10-05

[saldo] => -23

[team] => S.V.Z.W. Heren 2

[positie] => 8

)

[10] => stdClass Object

(

[afko] => Twente Buzzards HS 3

[ID] => 2294

[status] => Actief

[gespeeld] => 3

[percentage] => 33.3

[punten] => 2

[tegenscore] => 196

[eigenscore] => 151

[datum] => 2014-10-05

[saldo] => -45

[team] => Twente Buzzards Heren 3

[positie] => 9

)

)

[nummer] => OHS2C

[version] => 1.0

[aantal_teams] => 11

[id] => 373

[seizoen] => 2014-2015

[naam] => Oost Afdeling Heren Senioren 2e klasse C

[gewijzigd] => 2014-10-05 18:34:25

)

因此,现在您知道您要处理的是对象,而不是标量值或数组。

因此,请尝试以下代码:-

$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");

$data = json_decode($json);

if (count($data->stand)) {

// Open the table

echo "

// Cycle through the array

foreach ($data->stand as $idx => $stand) {

// Output a row

echo "

";

echo "

$stand->afko";

echo "

$stand->positie";

echo "

";

}

// Close the table

echo "

";

}

?>

2020-05-10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值