0

Here am Created the JSON Values in Static Way.

JSON Structure

{
"MatchType": {
    "inningsperteam": "1",
    "maxovers": "5",
    "players": "11"
},
"Innings": [
    {
        "noballs": "0",
        "BowlingDetail": [
            {
                "noballs": "0",
                "balls": "0",
                "maidens": "0",
                "player": "Bowler 12",
                "runs": "0",
                "wickets": "0",
                "bowlingposition": "1",
                "wides": "0"
            }
        ],
        "byes": "0",
        "battingteam": "Team 26",
        "overs": "0",
        "addpenaltyruns": "0",
        "legbyes": "0",
        "inplay": "true",
        "balls": "0",
        "InningsOvers": [],
        "declared": "false",
        "penaltyruns": "0",
        "bowlingteam": "Team 46",
        "runs": "0",
        "wickets": "0",
        "wides": "0",
        "completed": "false"
    }
],
"Umpire 1": "Umpire 12",
"Umpire 2": "Umpire 53",
"location": "England",
"Ground": "Oval",
"date": "20/6/2014",
"Club": [
    {
        "Team": {
            "Player": [
                {
                    "keeper": "false",
                    "captain": "false",
                    "firstname": "Batsman 1"
                },
                {
                    "keeper": "false",
                    "captain": "false",
                    "firstname": "Batsman 2"
                }
            ],
            "local": "1",
            "name": "Team 26",
            "toss": "false"
        },
        "local": "1",
        "name": "Club1"
    },
    {
        "Team": {
            "Player": [
                {
                    "keeper": "false",
                    "captain": "true",
                    "firstname": "Bowler 12"
                }
            ],
            "local": "2",
            "name": "Team 46",
            "toss": "true"
        },
        "local": "2",
        "name": "Club2"
    }
],
"CurrentPlayers": {
    "bowler": "Bowler 12",
    "playerA": "Batsman 1",
    "playerB": "Batsman 2"
}
}

BattingDetails JSON

[
{
    "BattingDetail": [
        {
            "balls": "0",
            "sixes": "0",
            "runs": "10",
            "player": "Batsman 1",
            "battingposition": "1",
            "fours": "0"
        },
        {
            "balls": "0",
            "sixes": "0",
            "runs": "0",
            "player": "Batsman 2",
            "battingposition": "1",
            "fours": "0"
        }
    ]
}
]

Coding

try {

        json_scores = new JSONObject(test_str);

        jsonArray = new JSONArray("["+test_str+"]");
        json_scores = jsonArray.getJSONObject(0);

        JSONArray nxt_test = new JSONArray(json_scores.getString("Innings"));

        String str = new JSONArray(json_scores.getString("Innings")).getJSONObject(0).getString("BattingDetail");
        JSONArray jArray = new JSONArray(str);
        for (int i = 0; i < jArray.length(); i++) {

            JSONObject json = new JSONObject();
            json = jArray.getJSONObject(i);

            if (json.getString("player").equalsIgnoreCase(player_name)) {

                jArray.getJSONObject(i).put("runs", "10");

            }
        }


        Log.v("Test Array", ""+nxt_test.put(0,new JSONObject().put("BattingDetail", jArray)));

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

I want to put the BattingDetail JSON array in Innings json array in JSON Structure.am not able solve this issue.can any one know help me to solve this issue.

1 Answer 1

1

Take your main json data into JSONObject.

JSONObject jsobj=new JSONObject(data);

JSONArray jsarBatting=new JSONArray(battingdetail);

JSONArray jsAr=jsobj.getJSONArray("innings"); 

JSONObject jsobj=  jsAr.getJSONObject(0); 

jsobj.put("BattingDetail",jsarBatting);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.