How to get the json array





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I want the array of custac from the given json data. But I dont know how to call custac from that. I want to get the custac values in an array. can anyone help
Here is my code



ArrayList<CustomerPayment> customerPayments = new 
ArrayList<CustomerPayment>();
try {
JSONArray resultVal = response.getJSONArray("Data");

int count=resultVal.length();
for(int i=0;i<count;i++)
{
CustomerPayment payment = new CustomerPayment(resultVal.getJSONObject(i));
customerPayments.add(payment);
}
} catch (JSONException e) {
e.printStackTrace();
}


Here is my jsondata



Result: {
"Result": {
"Status": 200,
"Success": true,
"Reason": "OK"
},
"Data": [
{
"CustomerID": "PTM_103",
"FirstName": "Dhanya",
"LastName": "Jacob ",
"NickName": "",
"FundAmount": 440,
"custac": [
{
"AccountTrackingId": "prod_4",
"ReferenceID": "",
"CustomerID": "PTM_103",
"OrderID": "ae3208287743908eb8e5911d8e7e73df",
"orderAmount": "0",
"CreatedAt": "prod"
}
]
},
...









share|improve this question

























  • @AbhayBohra Can you please explain

    – SRM
    Jan 3 at 9:51






  • 1





    inside the loop use resultVal.get(i).getJSONArray("custac");

    – Chandrani Chatterjee
    Jan 3 at 9:54











  • @SRM firstly, please check your JSON, it's invalid response

    – Nero
    Jan 3 at 9:54











  • @Nero Yes its correct..I have copied some only

    – SRM
    Jan 3 at 9:56











  • Possible duplicate of how to parse JSONArray in android

    – ADM
    Jan 3 at 10:06


















0















I want the array of custac from the given json data. But I dont know how to call custac from that. I want to get the custac values in an array. can anyone help
Here is my code



ArrayList<CustomerPayment> customerPayments = new 
ArrayList<CustomerPayment>();
try {
JSONArray resultVal = response.getJSONArray("Data");

int count=resultVal.length();
for(int i=0;i<count;i++)
{
CustomerPayment payment = new CustomerPayment(resultVal.getJSONObject(i));
customerPayments.add(payment);
}
} catch (JSONException e) {
e.printStackTrace();
}


Here is my jsondata



Result: {
"Result": {
"Status": 200,
"Success": true,
"Reason": "OK"
},
"Data": [
{
"CustomerID": "PTM_103",
"FirstName": "Dhanya",
"LastName": "Jacob ",
"NickName": "",
"FundAmount": 440,
"custac": [
{
"AccountTrackingId": "prod_4",
"ReferenceID": "",
"CustomerID": "PTM_103",
"OrderID": "ae3208287743908eb8e5911d8e7e73df",
"orderAmount": "0",
"CreatedAt": "prod"
}
]
},
...









share|improve this question

























  • @AbhayBohra Can you please explain

    – SRM
    Jan 3 at 9:51






  • 1





    inside the loop use resultVal.get(i).getJSONArray("custac");

    – Chandrani Chatterjee
    Jan 3 at 9:54











  • @SRM firstly, please check your JSON, it's invalid response

    – Nero
    Jan 3 at 9:54











  • @Nero Yes its correct..I have copied some only

    – SRM
    Jan 3 at 9:56











  • Possible duplicate of how to parse JSONArray in android

    – ADM
    Jan 3 at 10:06














0












0








0








I want the array of custac from the given json data. But I dont know how to call custac from that. I want to get the custac values in an array. can anyone help
Here is my code



ArrayList<CustomerPayment> customerPayments = new 
ArrayList<CustomerPayment>();
try {
JSONArray resultVal = response.getJSONArray("Data");

int count=resultVal.length();
for(int i=0;i<count;i++)
{
CustomerPayment payment = new CustomerPayment(resultVal.getJSONObject(i));
customerPayments.add(payment);
}
} catch (JSONException e) {
e.printStackTrace();
}


Here is my jsondata



Result: {
"Result": {
"Status": 200,
"Success": true,
"Reason": "OK"
},
"Data": [
{
"CustomerID": "PTM_103",
"FirstName": "Dhanya",
"LastName": "Jacob ",
"NickName": "",
"FundAmount": 440,
"custac": [
{
"AccountTrackingId": "prod_4",
"ReferenceID": "",
"CustomerID": "PTM_103",
"OrderID": "ae3208287743908eb8e5911d8e7e73df",
"orderAmount": "0",
"CreatedAt": "prod"
}
]
},
...









share|improve this question
















I want the array of custac from the given json data. But I dont know how to call custac from that. I want to get the custac values in an array. can anyone help
Here is my code



ArrayList<CustomerPayment> customerPayments = new 
ArrayList<CustomerPayment>();
try {
JSONArray resultVal = response.getJSONArray("Data");

int count=resultVal.length();
for(int i=0;i<count;i++)
{
CustomerPayment payment = new CustomerPayment(resultVal.getJSONObject(i));
customerPayments.add(payment);
}
} catch (JSONException e) {
e.printStackTrace();
}


Here is my jsondata



Result: {
"Result": {
"Status": 200,
"Success": true,
"Reason": "OK"
},
"Data": [
{
"CustomerID": "PTM_103",
"FirstName": "Dhanya",
"LastName": "Jacob ",
"NickName": "",
"FundAmount": 440,
"custac": [
{
"AccountTrackingId": "prod_4",
"ReferenceID": "",
"CustomerID": "PTM_103",
"OrderID": "ae3208287743908eb8e5911d8e7e73df",
"orderAmount": "0",
"CreatedAt": "prod"
}
]
},
...






android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 10:41









user1506104

1,58222244




1,58222244










asked Jan 3 at 9:47









SRMSRM

207




207













  • @AbhayBohra Can you please explain

    – SRM
    Jan 3 at 9:51






  • 1





    inside the loop use resultVal.get(i).getJSONArray("custac");

    – Chandrani Chatterjee
    Jan 3 at 9:54











  • @SRM firstly, please check your JSON, it's invalid response

    – Nero
    Jan 3 at 9:54











  • @Nero Yes its correct..I have copied some only

    – SRM
    Jan 3 at 9:56











  • Possible duplicate of how to parse JSONArray in android

    – ADM
    Jan 3 at 10:06



















  • @AbhayBohra Can you please explain

    – SRM
    Jan 3 at 9:51






  • 1





    inside the loop use resultVal.get(i).getJSONArray("custac");

    – Chandrani Chatterjee
    Jan 3 at 9:54











  • @SRM firstly, please check your JSON, it's invalid response

    – Nero
    Jan 3 at 9:54











  • @Nero Yes its correct..I have copied some only

    – SRM
    Jan 3 at 9:56











  • Possible duplicate of how to parse JSONArray in android

    – ADM
    Jan 3 at 10:06

















@AbhayBohra Can you please explain

– SRM
Jan 3 at 9:51





@AbhayBohra Can you please explain

– SRM
Jan 3 at 9:51




1




1





inside the loop use resultVal.get(i).getJSONArray("custac");

– Chandrani Chatterjee
Jan 3 at 9:54





inside the loop use resultVal.get(i).getJSONArray("custac");

– Chandrani Chatterjee
Jan 3 at 9:54













@SRM firstly, please check your JSON, it's invalid response

– Nero
Jan 3 at 9:54





@SRM firstly, please check your JSON, it's invalid response

– Nero
Jan 3 at 9:54













@Nero Yes its correct..I have copied some only

– SRM
Jan 3 at 9:56





@Nero Yes its correct..I have copied some only

– SRM
Jan 3 at 9:56













Possible duplicate of how to parse JSONArray in android

– ADM
Jan 3 at 10:06





Possible duplicate of how to parse JSONArray in android

– ADM
Jan 3 at 10:06












3 Answers
3






active

oldest

votes


















1














you have to make something like this



JSONObject jsonObject = new JSONObject(response);

JSONArray resultVal = jsonObject.getJSONArray("Data");





share|improve this answer































    0














    JSON data are objects parsed into a string for mostly NoSQL purposes and they can be parsed into objects. Gson is one of the libraries which is easy to use to parse your JSON data.



    If you get jsonData as the response string which has Data, the following code can parse the custac in the list of array. But, firstly you have to create an object for Data



    Data dataCollection = new Gson().fromJson(json,Data.class);


    Data must contain the attributes like CustomerID, FirstName, etc.



    For your case,



    class Data{
    private String CustomerID;
    private String FirstName;
    private String LastName;
    private String NickName;
    private int FundAmount;
    private ArrayList<Custac> custac;
    class Custac{
    // Write your attributes as shown above.
    }
    }





    share|improve this answer































      0














      Try This Code



      JSONArray custac;
      try {

      JSONArray resultVal = jsonObject.getJSONArray("Data");
      for (int i = 0; i < resultVal.length() - 1; i++) {
      jsonObject = resultVal.getJSONObject(i);
      custac = jsonObject.getJSONArray("custac");

      Log.d("TAG, custac + "");
      }
      } catch (JSONException e) {
      e.printStackTrace();
      }





      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%2f54019767%2fhow-to-get-the-json-array%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        you have to make something like this



        JSONObject jsonObject = new JSONObject(response);

        JSONArray resultVal = jsonObject.getJSONArray("Data");





        share|improve this answer




























          1














          you have to make something like this



          JSONObject jsonObject = new JSONObject(response);

          JSONArray resultVal = jsonObject.getJSONArray("Data");





          share|improve this answer


























            1












            1








            1







            you have to make something like this



            JSONObject jsonObject = new JSONObject(response);

            JSONArray resultVal = jsonObject.getJSONArray("Data");





            share|improve this answer













            you have to make something like this



            JSONObject jsonObject = new JSONObject(response);

            JSONArray resultVal = jsonObject.getJSONArray("Data");






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 3 at 10:00









            mohammed mahmoudmohammed mahmoud

            380210




            380210

























                0














                JSON data are objects parsed into a string for mostly NoSQL purposes and they can be parsed into objects. Gson is one of the libraries which is easy to use to parse your JSON data.



                If you get jsonData as the response string which has Data, the following code can parse the custac in the list of array. But, firstly you have to create an object for Data



                Data dataCollection = new Gson().fromJson(json,Data.class);


                Data must contain the attributes like CustomerID, FirstName, etc.



                For your case,



                class Data{
                private String CustomerID;
                private String FirstName;
                private String LastName;
                private String NickName;
                private int FundAmount;
                private ArrayList<Custac> custac;
                class Custac{
                // Write your attributes as shown above.
                }
                }





                share|improve this answer




























                  0














                  JSON data are objects parsed into a string for mostly NoSQL purposes and they can be parsed into objects. Gson is one of the libraries which is easy to use to parse your JSON data.



                  If you get jsonData as the response string which has Data, the following code can parse the custac in the list of array. But, firstly you have to create an object for Data



                  Data dataCollection = new Gson().fromJson(json,Data.class);


                  Data must contain the attributes like CustomerID, FirstName, etc.



                  For your case,



                  class Data{
                  private String CustomerID;
                  private String FirstName;
                  private String LastName;
                  private String NickName;
                  private int FundAmount;
                  private ArrayList<Custac> custac;
                  class Custac{
                  // Write your attributes as shown above.
                  }
                  }





                  share|improve this answer


























                    0












                    0








                    0







                    JSON data are objects parsed into a string for mostly NoSQL purposes and they can be parsed into objects. Gson is one of the libraries which is easy to use to parse your JSON data.



                    If you get jsonData as the response string which has Data, the following code can parse the custac in the list of array. But, firstly you have to create an object for Data



                    Data dataCollection = new Gson().fromJson(json,Data.class);


                    Data must contain the attributes like CustomerID, FirstName, etc.



                    For your case,



                    class Data{
                    private String CustomerID;
                    private String FirstName;
                    private String LastName;
                    private String NickName;
                    private int FundAmount;
                    private ArrayList<Custac> custac;
                    class Custac{
                    // Write your attributes as shown above.
                    }
                    }





                    share|improve this answer













                    JSON data are objects parsed into a string for mostly NoSQL purposes and they can be parsed into objects. Gson is one of the libraries which is easy to use to parse your JSON data.



                    If you get jsonData as the response string which has Data, the following code can parse the custac in the list of array. But, firstly you have to create an object for Data



                    Data dataCollection = new Gson().fromJson(json,Data.class);


                    Data must contain the attributes like CustomerID, FirstName, etc.



                    For your case,



                    class Data{
                    private String CustomerID;
                    private String FirstName;
                    private String LastName;
                    private String NickName;
                    private int FundAmount;
                    private ArrayList<Custac> custac;
                    class Custac{
                    // Write your attributes as shown above.
                    }
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 3 at 10:14









                    Sushant PaudelSushant Paudel

                    577




                    577























                        0














                        Try This Code



                        JSONArray custac;
                        try {

                        JSONArray resultVal = jsonObject.getJSONArray("Data");
                        for (int i = 0; i < resultVal.length() - 1; i++) {
                        jsonObject = resultVal.getJSONObject(i);
                        custac = jsonObject.getJSONArray("custac");

                        Log.d("TAG, custac + "");
                        }
                        } catch (JSONException e) {
                        e.printStackTrace();
                        }





                        share|improve this answer




























                          0














                          Try This Code



                          JSONArray custac;
                          try {

                          JSONArray resultVal = jsonObject.getJSONArray("Data");
                          for (int i = 0; i < resultVal.length() - 1; i++) {
                          jsonObject = resultVal.getJSONObject(i);
                          custac = jsonObject.getJSONArray("custac");

                          Log.d("TAG, custac + "");
                          }
                          } catch (JSONException e) {
                          e.printStackTrace();
                          }





                          share|improve this answer


























                            0












                            0








                            0







                            Try This Code



                            JSONArray custac;
                            try {

                            JSONArray resultVal = jsonObject.getJSONArray("Data");
                            for (int i = 0; i < resultVal.length() - 1; i++) {
                            jsonObject = resultVal.getJSONObject(i);
                            custac = jsonObject.getJSONArray("custac");

                            Log.d("TAG, custac + "");
                            }
                            } catch (JSONException e) {
                            e.printStackTrace();
                            }





                            share|improve this answer













                            Try This Code



                            JSONArray custac;
                            try {

                            JSONArray resultVal = jsonObject.getJSONArray("Data");
                            for (int i = 0; i < resultVal.length() - 1; i++) {
                            jsonObject = resultVal.getJSONObject(i);
                            custac = jsonObject.getJSONArray("custac");

                            Log.d("TAG, custac + "");
                            }
                            } catch (JSONException e) {
                            e.printStackTrace();
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 3 at 10:16









                            SnifferSniffer

                            7932823




                            7932823






























                                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%2f54019767%2fhow-to-get-the-json-array%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

                                MongoDB - Not Authorized To Execute Command

                                How to fix TextFormField cause rebuild widget in Flutter

                                Npm cannot find a required file even through it is in the searched directory