0

after sorting by ascending order the below is the json array i am getting

[{"id":0,"dependency":"no","position":0,"Itype":"textinput","label":"t01"},{"id":0,"dependency":"no","position":1,"label":"t02","type":"textarea"},{"id":1,"dependency":"no","position":2,"type":"textinput","label":"t03"},{"id":1,"dependency":"no","position":3,"type":"textarea","label":"t04"}]

I am building up text field or textaaarea according to type or itype in json array but am getting exception "NO value for id"

This is the code so far

//Sorting function called
                org.json.JSONArray finalSortedarray=Sort.Sort(formdataArray);
                System.out.println("After Function Called Array------------>"+finalSortedarray);
                /*for(int v=0;v<finalSortedarray.length();v++){
                    String sv=(String) formdataArray.getJSONObject(v).get("type");
                    System.out.println(sv);
                }*/
                    for(int v=0;v<finalSortedarray.length();v++){
                    JSONObject obj1=(JSONObject)finalSortedarray.getJSONObject(v);

                    Iterator<String> Nkeys= obj1.keys();
                    while(Nkeys.hasNext()){
                        String Nkey=Nkeys.next();
                        JSONArray Nval=obj.getJSONArray(Nkey);
                        System.out.println("NVAL IS----->"+Nval);
                        //formdataArray.getJSONObject(v).get("type");
                    }

                    }

Please Help

2 Answers 2

1
    for(int v=0;v<finalSortedarray.length();v++){

          JSONObject obj1=(JSONObject)finalSortedarray.getJSONObject(v);

                            String id =  obj1.getString("id");
                            String dependency=  obj1.getString("dependency");
                            String position=  obj1.getString("position");
                            //...

    }
Sign up to request clarification or add additional context in comments.

Comments

0

use like this

try{ 
    JSONArray array = new JSONArray(response)
    for(int i = 0; i<array.length();i++)
     { 
      JSONObject obj1 = array.getJSONObject(i);
      String id =  obj1.getString("id");
      String dependency=  obj1.getString("dependency");
      String position=  obj1.getString("position");
      String Itype=  obj1.getString("Itype");
      String label=  obj1.getString("label");
    }
  }
 catch(Exception e){
Log.d("","Error : "+e.toString());
}

happy to help

Comments

Your Answer

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