How to parse Json Arrays inside Json Arrays without key












0















Hi I am using json parsing, Following is my json response. Can any one help me with parsing,



{"success":

"{"mydata":

[
["Ramesh","Architect","Surat","1","2011/04/25","$123,123"],
["Suresh Ram","Accountant","Amdavad","2","2011/07/25","$121,121"],
["Naresh","Author","Up","3","2009/01/12","$76,000"],

........


My confusion is regarding parsing, response is very complex to parse.










share|improve this question


















  • 1





    Possible duplicate of Parse JSON Array without Key in Android

    – Nagendra Hari Karthick
    Nov 24 '18 at 4:39
















0















Hi I am using json parsing, Following is my json response. Can any one help me with parsing,



{"success":

"{"mydata":

[
["Ramesh","Architect","Surat","1","2011/04/25","$123,123"],
["Suresh Ram","Accountant","Amdavad","2","2011/07/25","$121,121"],
["Naresh","Author","Up","3","2009/01/12","$76,000"],

........


My confusion is regarding parsing, response is very complex to parse.










share|improve this question


















  • 1





    Possible duplicate of Parse JSON Array without Key in Android

    – Nagendra Hari Karthick
    Nov 24 '18 at 4:39














0












0








0








Hi I am using json parsing, Following is my json response. Can any one help me with parsing,



{"success":

"{"mydata":

[
["Ramesh","Architect","Surat","1","2011/04/25","$123,123"],
["Suresh Ram","Accountant","Amdavad","2","2011/07/25","$121,121"],
["Naresh","Author","Up","3","2009/01/12","$76,000"],

........


My confusion is regarding parsing, response is very complex to parse.










share|improve this question














Hi I am using json parsing, Following is my json response. Can any one help me with parsing,



{"success":

"{"mydata":

[
["Ramesh","Architect","Surat","1","2011/04/25","$123,123"],
["Suresh Ram","Accountant","Amdavad","2","2011/07/25","$121,121"],
["Naresh","Author","Up","3","2009/01/12","$76,000"],

........


My confusion is regarding parsing, response is very complex to parse.







android arrays json jsonparser






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 4:35









chrischris

1431428




1431428








  • 1





    Possible duplicate of Parse JSON Array without Key in Android

    – Nagendra Hari Karthick
    Nov 24 '18 at 4:39














  • 1





    Possible duplicate of Parse JSON Array without Key in Android

    – Nagendra Hari Karthick
    Nov 24 '18 at 4:39








1




1





Possible duplicate of Parse JSON Array without Key in Android

– Nagendra Hari Karthick
Nov 24 '18 at 4:39





Possible duplicate of Parse JSON Array without Key in Android

– Nagendra Hari Karthick
Nov 24 '18 at 4:39












2 Answers
2






active

oldest

votes


















1














I hope you can get success json object easily, so i am directly using jobSuccess here.



   ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
try {
JSONArray jarMyData=jobSuccess.getJSONArray("mydata");
for (int i = 0; i < jarMyData.length(); i++) {
JSONArray jar = jarMyData.getJSONArray(i);

DataModel dataModel=new DataModel();
dataModel.name=jar.getString(0);
dataModel.occupation=jar.getString(1);
dataModel.place=jar.getString(2);
dataModel.id=jar.getString(3);
dataModel.date=jar.getString(4);
dataModel.price=jar.getString(5);
arrDataModel.add(dataModel);
}
}catch (JSONException e)
{
Log.d("JSONException",e.toString());
}


You can create model class like this:



public class DataModel {
String name, occupation, place, id, date, price;
}


Note: i am not sure about fields name, so change their name according to your need.



Update
To get jobSuccess you need to :



String response="your json response in string format";
JSONObject jobSuccess=new JSONObject(response).getJSONObject("success");


Update 2



  // response is the json object you received from volley
jobSuccess=response.getJSONObject("TABLE_DATA");

ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
try {
// **Change below statement only**
JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));
for (int i = 0; i < jarMyData.length(); i++) {
JSONArray jar = jarMyData.getJSONArray(i);

DataModel dataModel=new DataModel();
dataModel.name=jar.getString(0);
dataModel.occupation=jar.getString(1);
dataModel.place=jar.getString(2);
dataModel.id=jar.getString(3);
dataModel.date=jar.getString(4);
dataModel.price=jar.getString(5);
arrDataModel.add(dataModel);
}
}catch (JSONException e)
{
Log.d("JSONException",e.toString());
}


Update Latest
You need to change this:



JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");


with this:



JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));





share|improve this answer


























  • thanks for your answer but will you help me with create model class for that

    – chris
    Nov 24 '18 at 7:22











  • @chris i have updated my answer check it.

    – Suraj Vaishnav
    Nov 24 '18 at 7:31











  • what is jobsucess

    – chris
    Nov 24 '18 at 8:18











  • jobSuccess is json object which you from success key from your json response

    – Suraj Vaishnav
    Nov 24 '18 at 8:20











  • but not giving option for jsonboject with data

    – chris
    Nov 24 '18 at 8:41



















0














here is how you can achieve it in Kotlin.



val obj = JSONObject(response)

val arrayOfArrays = obj.getJSONArray("mydata")

repeat(arrayOfArrays.length()){index->
val innerArray = arrayOfArrays.getJSONArray(index)
//either get the fields by their index
val name = innerArray.getString(0) //Ramesh
val field = innerArray.getString(1)//Architect
val third = innerArray.getString(2)//Surat
val id = innerArray.getString(3)//1
val date = innerArray.getString(4)//2011/04/25
val price = innerArray.getString(5)//$123,123
//or loop through the inner array
repeat(innerArray.length()){
//your inner array fields
}
}


suggestion:




  1. ask your backend developer to provide you with a list of objects instead of array of strings.


  2. use a JSON parsing library like: moshi, gson, jakson







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455162%2fhow-to-parse-json-arrays-inside-json-arrays-without-key%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I hope you can get success json object easily, so i am directly using jobSuccess here.



       ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    JSONArray jarMyData=jobSuccess.getJSONArray("mydata");
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    You can create model class like this:



    public class DataModel {
    String name, occupation, place, id, date, price;
    }


    Note: i am not sure about fields name, so change their name according to your need.



    Update
    To get jobSuccess you need to :



    String response="your json response in string format";
    JSONObject jobSuccess=new JSONObject(response).getJSONObject("success");


    Update 2



      // response is the json object you received from volley
    jobSuccess=response.getJSONObject("TABLE_DATA");

    ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    // **Change below statement only**
    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    Update Latest
    You need to change this:



    JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");


    with this:



    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));





    share|improve this answer


























    • thanks for your answer but will you help me with create model class for that

      – chris
      Nov 24 '18 at 7:22











    • @chris i have updated my answer check it.

      – Suraj Vaishnav
      Nov 24 '18 at 7:31











    • what is jobsucess

      – chris
      Nov 24 '18 at 8:18











    • jobSuccess is json object which you from success key from your json response

      – Suraj Vaishnav
      Nov 24 '18 at 8:20











    • but not giving option for jsonboject with data

      – chris
      Nov 24 '18 at 8:41
















    1














    I hope you can get success json object easily, so i am directly using jobSuccess here.



       ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    JSONArray jarMyData=jobSuccess.getJSONArray("mydata");
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    You can create model class like this:



    public class DataModel {
    String name, occupation, place, id, date, price;
    }


    Note: i am not sure about fields name, so change their name according to your need.



    Update
    To get jobSuccess you need to :



    String response="your json response in string format";
    JSONObject jobSuccess=new JSONObject(response).getJSONObject("success");


    Update 2



      // response is the json object you received from volley
    jobSuccess=response.getJSONObject("TABLE_DATA");

    ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    // **Change below statement only**
    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    Update Latest
    You need to change this:



    JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");


    with this:



    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));





    share|improve this answer


























    • thanks for your answer but will you help me with create model class for that

      – chris
      Nov 24 '18 at 7:22











    • @chris i have updated my answer check it.

      – Suraj Vaishnav
      Nov 24 '18 at 7:31











    • what is jobsucess

      – chris
      Nov 24 '18 at 8:18











    • jobSuccess is json object which you from success key from your json response

      – Suraj Vaishnav
      Nov 24 '18 at 8:20











    • but not giving option for jsonboject with data

      – chris
      Nov 24 '18 at 8:41














    1












    1








    1







    I hope you can get success json object easily, so i am directly using jobSuccess here.



       ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    JSONArray jarMyData=jobSuccess.getJSONArray("mydata");
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    You can create model class like this:



    public class DataModel {
    String name, occupation, place, id, date, price;
    }


    Note: i am not sure about fields name, so change their name according to your need.



    Update
    To get jobSuccess you need to :



    String response="your json response in string format";
    JSONObject jobSuccess=new JSONObject(response).getJSONObject("success");


    Update 2



      // response is the json object you received from volley
    jobSuccess=response.getJSONObject("TABLE_DATA");

    ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    // **Change below statement only**
    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    Update Latest
    You need to change this:



    JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");


    with this:



    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));





    share|improve this answer















    I hope you can get success json object easily, so i am directly using jobSuccess here.



       ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    JSONArray jarMyData=jobSuccess.getJSONArray("mydata");
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    You can create model class like this:



    public class DataModel {
    String name, occupation, place, id, date, price;
    }


    Note: i am not sure about fields name, so change their name according to your need.



    Update
    To get jobSuccess you need to :



    String response="your json response in string format";
    JSONObject jobSuccess=new JSONObject(response).getJSONObject("success");


    Update 2



      // response is the json object you received from volley
    jobSuccess=response.getJSONObject("TABLE_DATA");

    ArrayList<DataModel> arrDataModel=new ArrayList<DataModel>();
    try {
    // **Change below statement only**
    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel dataModel=new DataModel();
    dataModel.name=jar.getString(0);
    dataModel.occupation=jar.getString(1);
    dataModel.place=jar.getString(2);
    dataModel.id=jar.getString(3);
    dataModel.date=jar.getString(4);
    dataModel.price=jar.getString(5);
    arrDataModel.add(dataModel);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    Update Latest
    You need to change this:



    JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");


    with this:



    JSONArray jarMyData=new JSONObject(jobSuccess.getString("TABLE_DATA"));






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 24 '18 at 16:02

























    answered Nov 24 '18 at 4:45









    Suraj VaishnavSuraj Vaishnav

    1,5262518




    1,5262518













    • thanks for your answer but will you help me with create model class for that

      – chris
      Nov 24 '18 at 7:22











    • @chris i have updated my answer check it.

      – Suraj Vaishnav
      Nov 24 '18 at 7:31











    • what is jobsucess

      – chris
      Nov 24 '18 at 8:18











    • jobSuccess is json object which you from success key from your json response

      – Suraj Vaishnav
      Nov 24 '18 at 8:20











    • but not giving option for jsonboject with data

      – chris
      Nov 24 '18 at 8:41



















    • thanks for your answer but will you help me with create model class for that

      – chris
      Nov 24 '18 at 7:22











    • @chris i have updated my answer check it.

      – Suraj Vaishnav
      Nov 24 '18 at 7:31











    • what is jobsucess

      – chris
      Nov 24 '18 at 8:18











    • jobSuccess is json object which you from success key from your json response

      – Suraj Vaishnav
      Nov 24 '18 at 8:20











    • but not giving option for jsonboject with data

      – chris
      Nov 24 '18 at 8:41

















    thanks for your answer but will you help me with create model class for that

    – chris
    Nov 24 '18 at 7:22





    thanks for your answer but will you help me with create model class for that

    – chris
    Nov 24 '18 at 7:22













    @chris i have updated my answer check it.

    – Suraj Vaishnav
    Nov 24 '18 at 7:31





    @chris i have updated my answer check it.

    – Suraj Vaishnav
    Nov 24 '18 at 7:31













    what is jobsucess

    – chris
    Nov 24 '18 at 8:18





    what is jobsucess

    – chris
    Nov 24 '18 at 8:18













    jobSuccess is json object which you from success key from your json response

    – Suraj Vaishnav
    Nov 24 '18 at 8:20





    jobSuccess is json object which you from success key from your json response

    – Suraj Vaishnav
    Nov 24 '18 at 8:20













    but not giving option for jsonboject with data

    – chris
    Nov 24 '18 at 8:41





    but not giving option for jsonboject with data

    – chris
    Nov 24 '18 at 8:41













    0














    here is how you can achieve it in Kotlin.



    val obj = JSONObject(response)

    val arrayOfArrays = obj.getJSONArray("mydata")

    repeat(arrayOfArrays.length()){index->
    val innerArray = arrayOfArrays.getJSONArray(index)
    //either get the fields by their index
    val name = innerArray.getString(0) //Ramesh
    val field = innerArray.getString(1)//Architect
    val third = innerArray.getString(2)//Surat
    val id = innerArray.getString(3)//1
    val date = innerArray.getString(4)//2011/04/25
    val price = innerArray.getString(5)//$123,123
    //or loop through the inner array
    repeat(innerArray.length()){
    //your inner array fields
    }
    }


    suggestion:




    1. ask your backend developer to provide you with a list of objects instead of array of strings.


    2. use a JSON parsing library like: moshi, gson, jakson







    share|improve this answer




























      0














      here is how you can achieve it in Kotlin.



      val obj = JSONObject(response)

      val arrayOfArrays = obj.getJSONArray("mydata")

      repeat(arrayOfArrays.length()){index->
      val innerArray = arrayOfArrays.getJSONArray(index)
      //either get the fields by their index
      val name = innerArray.getString(0) //Ramesh
      val field = innerArray.getString(1)//Architect
      val third = innerArray.getString(2)//Surat
      val id = innerArray.getString(3)//1
      val date = innerArray.getString(4)//2011/04/25
      val price = innerArray.getString(5)//$123,123
      //or loop through the inner array
      repeat(innerArray.length()){
      //your inner array fields
      }
      }


      suggestion:




      1. ask your backend developer to provide you with a list of objects instead of array of strings.


      2. use a JSON parsing library like: moshi, gson, jakson







      share|improve this answer


























        0












        0








        0







        here is how you can achieve it in Kotlin.



        val obj = JSONObject(response)

        val arrayOfArrays = obj.getJSONArray("mydata")

        repeat(arrayOfArrays.length()){index->
        val innerArray = arrayOfArrays.getJSONArray(index)
        //either get the fields by their index
        val name = innerArray.getString(0) //Ramesh
        val field = innerArray.getString(1)//Architect
        val third = innerArray.getString(2)//Surat
        val id = innerArray.getString(3)//1
        val date = innerArray.getString(4)//2011/04/25
        val price = innerArray.getString(5)//$123,123
        //or loop through the inner array
        repeat(innerArray.length()){
        //your inner array fields
        }
        }


        suggestion:




        1. ask your backend developer to provide you with a list of objects instead of array of strings.


        2. use a JSON parsing library like: moshi, gson, jakson







        share|improve this answer













        here is how you can achieve it in Kotlin.



        val obj = JSONObject(response)

        val arrayOfArrays = obj.getJSONArray("mydata")

        repeat(arrayOfArrays.length()){index->
        val innerArray = arrayOfArrays.getJSONArray(index)
        //either get the fields by their index
        val name = innerArray.getString(0) //Ramesh
        val field = innerArray.getString(1)//Architect
        val third = innerArray.getString(2)//Surat
        val id = innerArray.getString(3)//1
        val date = innerArray.getString(4)//2011/04/25
        val price = innerArray.getString(5)//$123,123
        //or loop through the inner array
        repeat(innerArray.length()){
        //your inner array fields
        }
        }


        suggestion:




        1. ask your backend developer to provide you with a list of objects instead of array of strings.


        2. use a JSON parsing library like: moshi, gson, jakson








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 4:56









        seyed Jafariseyed Jafari

        376310




        376310






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455162%2fhow-to-parse-json-arrays-inside-json-arrays-without-key%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin