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

  • Home
  • SEARCH
  • 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 8199277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:08:14+00:00 2026-06-07T06:08:14+00:00

I am trying to parse JSON from a URL to then add data to

  • 0

I am trying to parse JSON from a URL to then add data to an array.
I am using the GSON library.

My JSON has the following format:

[
   {
      "img-src":"http://website.com/images/img1.png",
      "URL":"http://google.com"
   },
   {
      "img-src":"http://website.com/images/img2.jpg",
      "URL":"http://yahoo.com"
   }
]

I want to grab the above data in a separate thread, I have the following code:

public class Async extends AsyncTask<String, Integer, Object>{

        @Override
        protected String doInBackground(String... params) {



            return null;
        }


    }

How do I go about grabbing each “img-src” and “URL” values?

  • 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-07T06:08:15+00:00Added an answer on June 7, 2026 at 6:08 am

    Use this method to fetch your Data in an Array list

     public ArrayList<NewsItem> getNews(String url) {
        ArrayList<NewsItem> data = new ArrayList<NewsItem>();
    
        java.lang.reflect.Type arrayListType = new TypeToken<ArrayList<NewsItem>>(){}.getType();
        gson = new Gson();
    
        httpClient = WebServiceUtils.getHttpClient();
        try {
            HttpResponse response = httpClient.execute(new HttpGet(url));
            HttpEntity entity = response.getEntity();
            Reader reader = new InputStreamReader(entity.getContent());
            data = gson.fromJson(reader, arrayListType);
        } catch (Exception e) {
            Log.i("json array","While getting server response server generate error. ");
        }
        return data;
    }
    

    This should be how you should declare your ArrayList Type class (here its NewsItem)

      import com.google.gson.annotations.SerializedName;
        public class NewsItem   {
    
    @SerializedName("title")
    public String title;
    
    @SerializedName("content")
    public String title_details;
    
    @SerializedName("date")
    public  String date;
    
    @SerializedName("featured")
    public String imgRawUrl; 
    
    
    }
    

    Here is the WebSErvice Util Class.

    public class WebServiceUtils {
    
     public static HttpClient getHttpClient(){
            HttpParams httpParameters = new BasicHttpParams();
            // Set the timeout in milliseconds until a connection is established.
            int timeoutConnection = 50000;
            HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
            // Set the default socket timeout (SO_TIMEOUT) 
            // in milliseconds which is the timeout for waiting for data.
            int timeoutSocket = 50000;
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);           
            HttpClient httpclient = new DefaultHttpClient(httpParameters);          
            return httpclient;
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse this json data from the url but i get
I am trying to parse the json values from the following stream: {id: tag:search.xxxxx.com,2005:xxxxxxxxxxx}
I'm trying to load and parse json data from an external source into a
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing
I am trying to parse FB comments JSON, which I get from var url
I'm trying to return some JSON from my Spring webapp using Jackson and parse
I am trying to parse Json response from This URL . I have used
I'm trying to parse some JSON data from the Google AJAX Search API. I
I'm trying to parse data from a page of JSON in my ASP.NET MVC
I am trying to parse a JSON script from my server which contains a

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.