Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:30:34+00:00 2026-06-07T15:30:34+00:00

In the below code I am trying to populate the JSON array with JSON

  • 0

In the below code I am trying to populate the JSON array with JSON objects (book, and camera).

 [  {
  "camera":{
     "picture":"http:\/\/img7.flixcart.com\/image\-imacyb5emj5yztet.jpeg",
     "model":"Lumix DMC-FP3 Point & Shoot",
     "make":"Panasonic",
     "price":5830
  }
 },
{
  "camera":{
     "picture":"http:\/\/sp.sony-europe.com\/da.jpeg",
     "model":"Digital Still Camera - H Series - DSC-HX200V",
     "make":"Sony",
     "price":510
  }
 },
 {
  "book":{
     "description":"What is self, and how can a",
     "authors":"Douglas R Hofstadter",
     "price":650,
     "id":40724766,
     "title":"G\u00f6del, Escher, Bach: an Eternal Golden Braid"
  }
  },
 {
  "camera":{
     "picture":"http:\/\/www.usa.canon.com\/60d_586x186.gif",
     "model":"Digital SLR Camera EOS 60D",
     "make":"Canon",
     "price":999
  }
  },
   {
  "book":{
     "description":"Tgdfgf fgfg ",
     "authors":"Harold Abelson and Gerald Jay Sussman with Julie Sussman",
     "price":469,
     "id":51087,
     "title":"Structure and Interpretation of Computer Programs"
  }
},

]

public void getDetalFromServer() {
        // TODO Auto-generated method stub

        String  URL="xyz.php";
        HttpClient client= new DefaultHttpClient();
        HttpPost post=new HttpPost(URL);

        try {

            HttpResponse response =client.execute(post);
            HttpEntity getResEntity=response.getEntity();
            String result="";
            if(getResEntity!=null){
                result=EntityUtils.toString(getResEntity);
                System.out.println("result from server: "+result);

                bookDescription=new ArrayList<String>();
                bookAuthors=new ArrayList<String>();
                bookPrice=new ArrayList<String>();
                bookID=new ArrayList<String>();
                bookTitle=new ArrayList<String>();


                responseArray=new JSONArray(result);

                for(int i=0;i<responseArray.length();i++){

                    JSONObject bookObject=(JSONObject) responseArray.getJSONObject(i);
                                            bookDescription.add(bookObject.get("description").toString());
                                            bookAuthors.add(bookObject.get("authors").toString());                                              bookPrice.add(bookObject.get("price").toString());

bookID.add(bookObject.get(“id”).toString()); bookTitle.add(bookObject.get(“title”).toString());

                }                                       
            }

        } catch (Exception e) {
            // TODO: handle exception
        }
    }

Using this code I am able to just get the first object of the response. Now I am just trying to parse Music object from the response.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:30:38+00:00Added an answer on June 7, 2026 at 3:30 pm
                 responseArray=new JSONArray(result);
                  JSONObject bookObject=null;
                   JSONObject json_user1=null;
                   JSONObject json_user2=null;
                for(int i=0;i<responseArray.length();i++){
    
                    bookObject= responseArray.getJSONObject(i);
                     if (bookObject.has("book")){
                    json_user1 = bookObject.getJSONObject("book");   
                     bookDescription.add(json_user1.getString("description").toString());  
                      bookAuthors.add(json_user1.getString("authors").toString()); 
                 }
                    else if(bookObject.has("camera")){
                         json_user2 = bookObject.getJSONObject("camera"); 
                         /** Add Camera data in the lists here same as done for book */
                   }
              }
    

    Try this…. Inside your json array you have put json objects. so you need to retrieve json objects like book and camera from the array first and then from book object you can get the description and all… 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to change desktop image using below code: NSError *anError = nil;
Using the jQuery code below, I'm trying to take a JSON object to create
I am trying to create and populate an array of objects with information returned
I am trying to modify the sample code below. It currently populates a View
In the below code I'm trying to loop through each child node and append
I'm using the javascript code below trying to extract the number after gallery-entry_ in
In the code below i`m trying to read a list of selected projects and
I have been trying to access the below code DECLARE N_DEPTNO DEPT.DEPTNO %TYPE :=&DEPT_NUM;
In the below code, i am trying to reference an external .dll, which creates
I found the below code in the Internet, I'm trying to understand how Linux

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.