1

This is my JSON array,

[{
    "textinput": [{
        "position": 0,
        "dependency": "no",
        "id": 0,
        "label": "single1",
        "Itype": "textinput"
    }, {
        "position": 1,
        "dependency": "no",
        "id": 1,
        "label": "single2",
        "Itype": "textinput"
    }, {
        "position": 2,
        "dependency": "no",
        "id": 2,
        "label": "single3",
        "Itype": "textinput"
    }, {
        "position": 3,
        "dependency": "no",
        "id": 3,
        "label": "single4",
        "Itype": "textinput"
    }, {
        "position": 4,
        "dependency": "no",
        "id": 4,
        "label": "single5",
        "Itype": "textinput"
    }, {
        "position": 5,
        "dependency": "no",
        "id": 5,
        "label": "single6",
        "Itype": "textinput"
    }]
}]

I would like to get help in counting the number of position in the above array.

4
  • no of count of position is jsonarray.length.... Commented Jul 28, 2016 at 6:03
  • what exactly you looking for you want to get sum of position??if not then you just need jsonArraylength it give count of your responses. Commented Jul 28, 2016 at 6:24
  • not the sum but how many " position" are there in the array @AndroidDeveloper Commented Jul 28, 2016 at 6:26
  • then put your whole json. because json never starts with JsonArray Its always starts with root Json Object Commented Jul 28, 2016 at 6:29

2 Answers 2

1

You missed out the j there :P

try {
     JSONArray jsonArray = new JSONArray("Your response");    
     int count = jsonArray.getJSONObject(0).getJSONArray("textinput").length();
 } catch (JSONException e) {
     e.printStackTrace();
 }
Sign up to request clarification or add additional context in comments.

Comments

0

String[] array = text.split("position"); //text your reponse json String

int count = array.length-1; //the number of position

Comments

Your Answer

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