我尝试创建一个JSONObject,其中包含一组由字符串组织的其他JSONObjects的数组?例如,我想创建一个JSONObject,其中包含一个按比赛日期组织的固定装置对象的数组。
为了给您一个视觉参考,我正在努力实现以下目标:
这是我到目前为止尝试过的,但只是无法使其工作。
这是JSON数据源。
为了给您一个视觉参考,我正在努力实现以下目标:
JSONObject (JSONArray("Object 10/10/12" {(fixtures content)(fixtures content)}")
("Object 11/10/12" {(fixtures content)(fixtures content)}"))
这是我到目前为止尝试过的,但只是无法使其工作。
String matchDate1 = null;
JSONArray datesArray = null;
JSONObject fixturesInfo = null;
JSONArray fixturesInfoArray = null;
String matchDateTemp = null;
for(int f = 0; f < fixturesArray.length(); f++){
JSONObject matchDateDict = fixturesArray.getJSONObject(f);
matchDate1 = matchDateDict.getString("matchdate");
JSONArray fixturesInfoDict = fixturesInfo.getJSONArray(matchDate1);
if(fixturesInfoDict == null){
tempArray = null;
} else {
tempArray = fixturesInfoDict;
}
if(matchDateTemp != matchDate1){
fixturesInfoArray.put(matchDate1);
}
matchDateTemp = matchDate1;
tempArray.put(fixturesArray.getJSONObject(f));
fixturesInfo.put(matchDate1, tempArray);
}
Log.v("MyFix", "fixturesInfo = " + fixturesInfo);
}catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是JSON数据源。
{
"code": 200,
"error": null,
"data": {
"fixtures": [{
"kickoff": "15:00:00",
"matchdate": "2012-07-14",
"homescore": null,
"awayscore": null,
"attendance": null,
"homepens": null,
"awaypens": null,
"division_id": "5059",
"division": "Testing 1",
"comp": "LGE",
"location": null,
"fixture_note": null,
"hometeam_id": "64930",
"hometeam": "Team 1",
"awayteam_id": "64933",
"awayteam": "Team 4"
}, {
"kickoff": "15:00:00",
"matchdate": "2012-07-14",
"homescore": null,
"awayscore": null,
"attendance": null,
"homepens": null,
"awaypens": null,
"division_id": "5059",
"division": "Testing 1",
"comp": "LGE",
"location": null,
"fixture_note": null,
"hometeam_id": "64935",
"hometeam": "Team 6",
"awayteam_id": "64937",
"awayteam": "Team 8"
}, {
"kickoff": "15:00:00",
"matchdate": "2012-07-28",
"homescore": null,
"awayscore": null,
"attendance": null,
"homepens": null,
"awaypens": null,
"division_id": "5059",
"division": "Testing 1",
"comp": "LGE",
"location": null,
"fixture_note": null,
"hometeam_id": "64930",
"hometeam": "Team 1",
"awayteam_id": "64931",
"awayteam": "Team 2"
}, {
"kickoff": "15:00:00",
"matchdate": "2012-07-28",
"homescore": null,
"awayscore": null,
"attendance": null,
"homepens": null,
"awaypens": null,
"division_id": "5059",
"division": "Testing 1",
"comp": "LGE",
"location": null,
"fixture_note": null,
"hometeam_id": "64930",
"hometeam": "Team 1",
"awayteam_id": "64931",
"awayteam": "Team 2"
}]
}
}