如何获得团队A和团队b之类的团队名称

时间:2016-05-02 11:12:23

标签: android json

results: {   //this is json api

Match: [
    {
    group: "",
    matchid: "193894",
    mtype: "t20",
    series_id: "12437",
    series_name: "Indian Premier League, 2016",
    stage: "heat",
    status: "pre",
    MatchNo: "Match 30",
    Venue: {
    venueid: "90",
    content: "M.Chinnaswamy Stadium, Bengaluru"
    },
    StartDate: "2016-05-02T20:00:00+05:30",
    EndDate: "2016-05-03T00:00:00+05:30",
    MatchTimeSpan: "Day-Night",
    Team: [  
    {
    Team: "Bangalore",
    role: "",
    teamid: "1105"
    },
    {
    Team: "Kolkata",
    role: "",
    teamid: "1106"
    }
    ],
    date_match_start: "20160502143000",
    date_match_end: "20160502183000"
    }

如何获得像班加罗尔和加尔各答这样的球队名称。

1 个答案:

答案 0 :(得分:1)

你必须记住@Shree Krishna的评论。您可以阅读下面的json数据

    try {
        JSONObject object = new JSONObject(your_response);//your json result
        JSONArray array = object.getJSONArray("Match");
        JSONObject firstMatch = array.getJSONObject(0);//first position of array

        JSONArray teams = firstMatch.getJSONArray("Team");//read teams details
        JSONObject firstTeam = teams.getJSONObject(0);//get first team
        String team1Name = firstTeam.getString("Team");
        JSONObject secondTeam = teams.getJSONObject(1);//get second team
        String team2Name = secondTeam.getString("Team");
    } catch (JSONException e) {
        e.printStackTrace();
    }