0

通过搜索这个网站,我几乎可以得到我所有的答案。谢谢!

不幸的是,我在解析包含足球统计数据的文件时遇到了麻烦,这让我很烦恼。下面的 div 标签似乎有多个嵌套元素,我只是不知道如何解析。谁能指出我正确的方向?

div id 是 player_data,我知道了,我基本上想要玩家的数据,例如:

8780,Matt,Ryan,Atl,2,Boston College,76.0....等

div 标签包含 2 名球员 Matt Ryan 和 Aaron Rogers 的数据。原始文件包含使用以下相同格式的 200 多个播放器。

<div id="player_data" style="display: none;">
[{"player_id":8780,"position":"QB","first_name":
"Matt","last_name":"Ryan","team_alias":"Atl","number":"2","college":"Boston 
College","height":76.0,"weight":217.0,"age":27,"team_city":
"Atlanta","team_name":"Falcons","experience":6,"next_matchup":      [{"opponent":"Oak","game_datetime":"10/14, 1:00 

PM"}],"salary":18408,"injured":false,"pstats":
[{"year":10015,"yds":714,"paint":2,"td":5,"g":2},
{"year":2012,"yds":1507,"paint":3,"td":13,"g":5},
{"year":2011,"yds":4177,"paint":12,"td":29,"g":16}],"rstats":
[{"year":10015,"yds":4,"td":0},{"year":2012,"yds":52,"td":1},
{"year":2011,"yds":84,"td":2}],"recstats":[{"year":10015,"rec":0,"yds":0,"td":0},
{"year":2012,"rec":0,"yds":0,"td":0},{"year":2011,"rec":0,"yds":0,"td":0}],"fumstats":
[{"year":10015,"fl":1},{"year":2012,"fl":1},{"year":2011,"fl":3}],"exstats":
[{"year":10015,"twopts":0},{"year":2012,"twopts":0},{"year":2011,"twopts":0}],"dstats":[]},
{"player_id":7200,"position":"QB","first_name":"Aaron","last_name":"Rodgers","team_alias":"
GB","number":"12","college":"California","height":74.0,"weight":225.0,"age":28,"team_city":
"Green Bay","team_name":"Packers","experience":9,"next_matchup":
[{"opponent":"@Hou","game_datetime":"10/14, 8:20 
PM"}],"salary":17721,"injured":false,"pstats":
[{"year":10015,"yds":562,"paint":2,"td":7,"g":2},
{"year":2012,"yds":1307,"paint":4,"td":10,"g":5},
{"year":2011,"yds":4643,"paint":6,"td":45,"g":15}],"rstats":
[{"year":10015,"yds":70,"td":0},{"year":2012,"yds":108,"td":0},
{"year":2011,"yds":257,"td":3}],"recstats":[{"year":10015,"rec":0,"yds":0,"td":0},
{"year":2012,"rec":0,"yds":0,"td":0},{"year":2011,"rec":0,"yds":0,"td":0}],"fumstats"
:[{"year":2012,"fl":0},{"year":2011,"fl":0}],"exstats":[{"year":10015,"twopts":0},
{"year":2012,"twopts":0},{"year":2011,"twopts":0}],"dstats":[]}]}]</div>
4

1 回答 1

0

玩家数据为 JSON 格式。您可以使用 Java JSON 库对其进行解析,请参阅此处的 Java JSON 库。您的示例中的 JSON 似乎无效(使用此验证器检查),因此在解析该 JSON 时可能会导致一些问题。

于 2012-10-11T08:14:24.860 回答