learn json

ArrayList<Countries> listCountries = new ArrayList<>();//country
        ArrayList<Detail> listDetails = new ArrayList<>();//listDetail
        ArrayList<Detail> listSub =  new ArrayList<>();//List Sub

        Countries countries = new Countries();
        countries.setId("1");
        countries.setName("Sim");
        countries.setGender("M");
        countries.setCountry("khompong Chhnang");
        countries.setPostalCode("225566");
        //Add Countries object to ArrayList
        listCountries.add(countries);

        Detail detail =  new Detail();
        detail.setPhone("09659694146");
        detail.setAddress("11H");
        //Add Detail object to ArrayList
        listDetails.add(detail);

        Detail detail1 =  new Detail();
        detail1.setPhone("2222");
        detail1.setAddress("tttt2");
        listSub.add(detail1);

        JSONObject jsonObject_sub = new JSONObject();
        JSONArray jsonArray_sub = new JSONArray();
        for (int i = 0; i < listSub.size(); i++){
            try {
                jsonObject_sub.put("Phone",listSub.get(i).getPhone());
                jsonObject_sub.put("Address",listSub.get(i).getAddress());
                jsonArray_sub.put(jsonObject_sub);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        JSONObject jb = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i<listDetails.size(); i++){
            //convert to JSONObject
            try {
                jb.put("Address",listDetails.get(i).getAddress());
                jb.put("Phone",listDetails.get(i).getPhone());
                jb.put("sub_detail",jsonArray_sub);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        //convert JSONObject to JSONArray
        for (int i = 0; i < 3; i++){
            jsonArray.put(jb);
        }


        JSONObject jsonObject = new JSONObject();
        for (int i=0; i<listCountries.size(); i++){
            try {
                //convert to JSONObject
                jsonObject.put("id",listCountries.get(i).getId());
                jsonObject.put("name",listCountries.get(i).getName());
                jsonObject.put("gender",listCountries.get(i).getGender());
                //put JSONArray into JSONObject
                jsonObject.put("detail",jsonArray);
                jsonObject.put("country",listCountries.get(i).getCountry());
                jsonObject.put("postal_code",listCountries.get(i).getPostalCode());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Log.d(">>>", "jsonObject: "+jsonObject);
        }


================Output===========================================================
  {"id":"1","name":"Sim","gender":"M","detail":[{"Address":"11H","Phone":"09659694146","sub_detail":[{"Phone":"2222","Address":"tttt2"}]},{"Address":"11H","Phone":"09659694146","sub_detail":[{"Phone":"2222","Address":"tttt2"}]},{"Address":"11H","Phone":"09659694146","sub_detail":[{"Phone":"2222","Address":"tttt2"}]}],"country":"khompong Chhnang","postal_code":"225566"}

4
2
John Satta 125 points

                                    {
	
}

4 (2 Votes)
0
4.22
9
Zac 105 points

                                    {
	&quot;name&quot; : &quot;data&quot;
}

4.22 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
setting.json file learn json step by step json setting file example learning json is json hard to learn learn json free json tutorial for beginners how to learn json learn with json should i learn json json how to how to work with json how to build a json working wiht json json file structure json tutorial what is in json file work json json file exemple json using data jason using data how to use data from json file json.strin how json looks like how to use data from json make json data json data string format JSON sjson structure get data from json format how to do json example of a json file in js store data via json junderstand son output what can i do with json scripts json string format how to make json output in browser more organized why do we need classes for json data JsonResult only apear first json forma where json is used how json how json works javascript json file what is json file used for? json tutorial javascript json learning how to setup json in html how does json look like set vaibla of json file json call data how to store data in json datastructure what does json look like how to wor on json how to create a json file tutorial json data storage why we use json in javascript how json is written javascript what does .json do json response what does .json do intro json website json under json? where to run json what is the syntax to store data in json file how to json file whats a json where to find json data data to json how to build with json what is th euse of json json get started what json used for read json data what json is used for json file start json program json where we use waht is json json setup what is the use of json file where to write json code how do i use json what is .json() is used for? what is json() is used for? code to store the data in JSON in the build. how to store data in json in build json file what is what json Json laearn how to make json data file use json in script how to execute json file creating json files json used for what does json file do? how to use a json file what is s json file what is the emaning of json data why use json how to make json how to display text within in json data use data from a json file why is json called json why is json used what is a json used for how to make a json file object how to make a json file and object how to make a json file an object working with json data for website what is json file used for using json data whats json how to use a .json file whats is json json uses a/an json how to use json files use json using json using files in json creating json how json is created json simplefied how to use ! in json how to start a json file purpose of json json javas uderstanding json output how i can write my json response what does json.data do? how to realize text is a json how to compile json file what is use of json file json data contains code json parse storing wrong data html json knowledge how to use &quot; in json how to write json data why to use json how does json object look javascript save json to file and edit-json-file how to store datein json what is json for what is used for where is json used handle json data what does json do what does a simple json file how to make a simple json file what does json output look like why we use GET in json how to use json file how to make data JSON json practice json store data what does json do? making json data readable i have a json file how to store data in json file how does json format looks like how does json looks json file explained how to organize json files json information explanation of json working with json how to write json learn json api data in json file file.json store data json use website write to json json file tutorial whats a json file look like store data in json file want Json what is .json() in js learn json how to make json file json is used to json data is stored as objects basic.json in simple switch HOW TO CREATE JSON IN WEBSITE what is the use of json json file what are json files used for what does json file do make your own json file what is is JSON why json is used why json when to use json json code how to get data in json format json data files data.json file how to start a json html? create a json file javascript simplefa json explaining .json files json example how to organize a json with weekly data How to write a json json what is what is json json example format json file example implement json in javascriot local file json not change after text change from json in agnular json is used for make json file available how to create json file how to make a json file how to use json use of json make a json file write your own json file what is json used for how to set up a json file
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source