我正在尝试提取包含主队和客队的目标的结果对象。如何获取这两个项的整数值,然后将它们分配给数组列表?
"fixtures": [
"_links": {
"self": {
"href": "http://api.football-data.org/v1/fixtures/150840"
},
"soccerseason": {
"href": "http://api.football-data.org/v1/soccerseasons/426"
},
"homeTeam": {
"href": "http://api.football-data.org/v1/teams/62"
},
"awayTeam": {
"href": "http://api.football-data.org/v1/teams/73"
}
},
"date": "2016-08-13T14:00:00Z",
"status": "FINISHED",
"matchday": 1,
"homeTeamName": "Everton FC",
"awayTeamName": "Tottenham Hotspur FC",
"result": {
"goalsHomeTeam": 1,
"goalsAwayTeam": 1
}
]
我的代码:
try {
JSONObject jsonObj = new JSONObject(jsonData);
JSONArray ja = jsonObj.getJSONArray("fixtures");
matchList.clear(); //Clears the ArrayList.
for (int i = 0; i < ja.length(); i++) //iterating in JSONArray
{
JSONObject jo = ja.getJSONObject(i);
int matchDay = jo.getInt(MATCH_DAY);
String homeTeamName = jo.getString(HOME_TEAM_NAME);
String awayTeamName = jo.getString(AWAY_TEAM_NAME);
String date = jo.getString(DATE);
JSONObject result = jo.getJSONObject(RESULT);
int goalsHometeam = result.getInt(GOALS_HOME);
int goalsAwayTeam = result.getInt(GOALS_AWAY);
String status = jo.getString(STATUS);
Match match = new Match();
match.setMatchday(matchDay);
match.setHomeTeamName(homeTeamName);
match.setAwayTeamName(awayTeamName);
match.setDate(date);
match.setGoalsHometeam(goalsHometeam);
match.setGoalsAwayTeam(goalsAwayTeam);
match.setStatus(status);
答案 0 :(得分:0)
#pragma once
class workoutlogger
{
public:
workoutlogger();
~workoutlogger();
int viewinfo();
int log();
};
为JSON
。
更新not a valid JSON
:
JSON Structure
{
"_links": {
"self": {
"href": "http://api.football-data.org/v1/fixtures/150840"
},
"soccerseason": {
"href": "http://api.football-data.org/v1/soccerseasons/426"
},
"homeTeam": {
"href": "http://api.football-data.org/v1/teams/62"
},
"awayTeam": {
"href": "http://api.football-data.org/v1/teams/73"
}
},
"date": "2016-08-13T14:00:00Z",
"status": "FINISHED",
"matchday": 1,
"homeTeamName": "Everton FC",
"awayTeamName": "Tottenham Hotspur FC",
"result": {
"goalsHomeTeam": 1,
"goalsAwayTeam": 1
}
}
&#13;