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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:41:34+00:00 2026-06-01T03:41:34+00:00

Hello Android programmers, I am working on parsing a website in my application. This

  • 0

Hello Android programmers,

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

The problem with this code segment is that it is not getting the rates in order.

    private class DownloadWebPageTask extends AsyncTask<String, Void, ArrayList<Double>>
{
    protected ArrayList<Double> doInBackground(String... urls)
    {
        ArrayList<Double> response = new ArrayList<Double>();
        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(Double.parseDouble(ratesObj.getString(keys.next())));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return response;
    }
    @Override
    protected void onPostExecute(ArrayList<Double> result)
    { 
        currency_values = result;
    }

To test this class, I used the following line of code:

   test.setText(currency_values.get(0).toString()); //test is a TextView

The answer should be 3.6733 (if you look at the website), because it is the first rate in the ArrayList. However, it returns 82.894997, which is later found under JPY.

Why would this be happening? Does anyone have a fix for this?

  • 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-01T03:41:35+00:00Added an answer on June 1, 2026 at 3:41 am

    That would be because JSONObject is probably using a simple Map (not a sorted one) to store the field/value combinations. The solution is to update your JSON, actually. The problem is that you want an array of rates. Like this:

     "rates": [
        { "AED": 3.6733 },
        {"AFN": 48.32},
        {"ALL": 104.959999},
        ...
     ]
    

    Actually, I lied, a rate should look like this:

    { "key": "AED",
      "value": 3.6733 
    }
    

    Edit:
    To sort the results, store them first into an object with a String field and a Double field, then you can sort them by name and display them in order.

    • 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 making a currency application and to do this, I
Hello dear programmers, I am very new to android application development and for practice
hello fellow programmers, I followed a tutorial at http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php to send a String encrypted
I have developed the Hello World Android application using Eclipse. I can run the
Hello Android programmers, I was trying to make a screen that has an EditText
Hello android developers, I was struggling to get this work but failed and now
hi when i run hello Android test http://developer.android.com/resources/tutorials/testing/helloandroid_test.html i got the following errors java.lang.RuntimeException:
Flush with success on getting hello Android to run, I'm working on the tutorial
Hello Android Experts, I have the following layout: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content android:gravity=center_horizontal> <ImageButton
Hello my favorite help resource... I am a average android programmer making an application

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.