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 7730733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:17:59+00:00 2026-06-01T06:17:59+00:00

I am working on parsing a website in my application. This is the website:

  • 0

I am working on parsing a website in my application.

This is the website: https://raw.github.com/currencybot/open-exchange-rates/master/latest.json

Since I have had some trouble with this, I first tried to get the entire website using a class that extends AsyncTask.

Here is the code which gets EVERYTHING from the website above:

     private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        String response = "";
        for (String url : urls)
        {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try
            {
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

                BufferedReader buffer = new BufferedReader(
                        new InputStreamReader(content));
                String s = "";
                while ((s = buffer.readLine()) != null) {
                    response += s;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return response;
    }
}

However, if you go to the website, I only want the portion after rates. I have to edit the above code so it only returns what I need.

Based on what I understand, I know that I need to change String response to an ArrayList, and I need to change the while loop, but I don’t know what I should do exactly.

I tried using the following code to change the method, but it did NOT work.

     private class DownloadWebPageTask extends AsyncTask<String, Void, ArrayList<String>> {
    @Override
    protected ArrayList<String> doInBackground(String... urls) 
    {
        ArrayList<String> response = new ArrayList<String>();
        for (String url : urls)
        {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try
            {
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

                BufferedReader buffer = new BufferedReader(
                        new InputStreamReader(content));
                String s = response.toString();
                while ((s = buffer.readLine()) != null)
                {
                    JSONArray ja = new JSONArray(s);
                    for (int i = 0; i < ja.length(); i++) {
                        JSONObject jo = (JSONObject) ja.get(i);
                        response.add(jo.getString("rates"));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return response;
    }
}

Any help would be greatly appreciated.

@Dheeraj, UPDATE:

   while ((s = buffer.readLine()) != null)
   {
         JSONArray ja = new JSONObject().getJSONArray("rates"); 
        response.add(ja.toString()); 
   }

This is what I have so far Dheeraj. I am stuck on how to provide the buffer to a JSONObject. Can you help me?

  • 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-01T06:18:01+00:00Added an answer on June 1, 2026 at 6:18 am
    1. Provide the entire buffer you get from the network to a
      JSONObject.
    2. [Edit: Corrected thanks to @MisterSquonk] From the JSONObject get the value of “rates” as another JSONObject using getJSONObject("rates").
    3. Iterate over the keys of the “rates” object to get its values.

    Here’s the code:

    private class DownloadWebPageTask extends AsyncTask<String, Void, ArrayList<String>> {
        @Override
        protected ArrayList<String> doInBackground(String... urls) {
            ArrayList<String> response = new ArrayList<String>();
            for (String url : urls) {
                DefaultHttpClient client = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(url);
                try {
                    HttpResponse execute = client.execute(httpGet);
                    InputStream content = execute.getEntity().getContent();
                    InputStreamReader isr = new InputStreamReader(content);
                    StringBuilder sb = new StringBuilder();
                    char[] buffer = new char[1024];
                    while (isr.read(buffer) != -1) {
                        sb.append(buffer);
                    }
                    JSONObject jobj = new JSONObject(sb.toString());
                    JSONObject ratesObj = jobj.getJSONObject("rates");
                    Iterator<String> keys = ratesObj.keys();
                    while (keys.hasNext()) {
                        response.add(ratesObj.getString(keys.next()));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return response;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Android programmers, I am working on parsing a website in my application. This
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
I'm working on a local application ( it's not a website or nothing related
I'm developing an application for a client's website. Here's the story, this company uses
Working on parsing a bunch of databases put together in an older, more freewheeling
I'm parsing an RSS feed with NSXMLParser and it's working fine for the title
I'm working in C#/.NET and I'm parsing a file to check if one line
I am working on a javascript project which involves parsing xml data. I have
I'm working on some code that deals with parsing files (mainly XML, but there
A web app I'm working on requires frequent parsing of diverse web resources (HTML,

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.