Android的创建JSON对象的JSON数组 [英] Android create a JSON array of JSON Objects

查看:82
本文介绍了Android的创建JSON对象的JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜没有人知道如何创建一个包含在每个对象包含几个对象对象数组?我刚才似乎无法让我的头轮它

结构应该像这样

 阵{[对象] {子对象,子对象}
      [对象] {子对象,子对象}
     }
 

继承人是我迄今为止

 的JSONObject的obj =新的JSONObject(json2);
            JSONObject的objData = obj.getJSONObject(数据);
            fixturesArray = objData.getJSONArray(固定装置);

            JSONArray FixArray =新JSONArray();


            对于(INT T = 0; T< fixturesArray.length();吨++){
            JSONObject的fixObj = fixturesArray.getJSONObject(T);
            串Matchdate = fixObj.getString(matchdate);
            JSONObject的选项dateObj = DateObj.put(Matchdate,选项dateObj);
 

我的继承人JSON基本上我有什么,如果是固定装置的进给我要命令他们到日期数组

  {
    code:200,
    错误:空,
    数据:{
        夹具:
            {
                开球:15时00分零零秒,
                matchdate:2012-07-28,
                homescore:空,
                awayscore:空,
                考勤:空,
                homepens:空,
                awaypens:空,
                division_id:5059,
                师:测试1,
                补偿:LG电子,
                位置:空,
                fixture_note:空,
                hometeam_id:64930,
                hometeam:1队,
                awayteam_id:64931,
                awayteam:二队
            },{
                开球:15时00分零零秒,
                matchdate:2012-07-28,
                homescore:空,
                awayscore:空,
                考勤:空,
                homepens:空,
                awaypens:空,
                division_id:5059,
                师:测试1,
                补偿:LG电子,
                位置:空,
                fixture_note:空,
                hometeam_id:64930,
                hometeam:1队,
                awayteam_id:64931,
                awayteam:二队
            }
        ]
    }
}
 

解决方案

你的意思是:

 的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());

这篇关于Android的创建JSON对象的JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆