且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的创建JSON对象的JSON数组

更新时间:2023-01-16 21:16:39

你的意思是:

 的JSONObject的obj =新的JSONObject();
obj.put(×,1);
JSONObject的parent_object =新的JSONObject();
parent_object.put(孩子,OBJ);
JSONArray数组=新JSONArray(parent_object.toString());
 

hi does anyone know how to create a Array that contains objects that in each objects contain several objects? i just can't seem to get my head round it

the structure should look like this

Array{[object]{subobject,subobject}
      [object]{subobject,subobject}
     }

heres what i have so far

JSONObject obj = new JSONObject(json2);    
            JSONObject objData = obj.getJSONObject("data");
            fixturesArray = objData.getJSONArray("fixtures");

            JSONArray FixArray = new JSONArray();


            for(int t = 0; t < fixturesArray.length(); t++){
            JSONObject fixObj = fixturesArray.getJSONObject(t);
            String Matchdate = fixObj.getString("matchdate");
            JSONObject DateObj = DateObj.put(Matchdate, DateObj);

heres my JSON essentially what i have if is a feed of fixtures i need to order them in to arrays of dates

{
    "code":200,
    "error":null,
    "data":{
        "fixtures":[
            {
                "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"
            }
        ]
    }
}

Do you mean that?:

JSONObject obj = new JSONObject();
obj.put("x", "1");
JSONObject parent_object = new JSONObject();
parent_object.put("child", obj);
JSONArray array = new JSONArray(parent_object.toString());