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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:11:28+00:00 2026-05-21T03:11:28+00:00

I got an error in parsing JSON on Android. This is my JSON method:

  • 0

I got an error in parsing JSON on Android. This is my JSON method:

void examineJSONFile()
    {
        try
        {
            //String x = "";
            String y = "";
            InputStream is = this.getResources().openRawResource(R.raw.utf);
            Writer writer = new StringWriter();
            char[] buffer = new char[1024];

            try {
              BufferedReader reader = new BufferedReader(
                new InputStreamReader(is, "UTF-8")
              );
              int n;
              while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
              }
            } finally {
              is.close();
            }

            String jsontext = writer.toString();
            JSONArray entries = new JSONArray(jsontext);


            int j;
            for (j=0;j<entries.length();j++)
            {
                JSONObject post = entries.getJSONObject(j);
                y += post.getString("description") + "\n";
            }
            txt_beschreibung.setText(y);
        }
        catch (Exception je)
        {
            txt_beschreibung.setText("Error w/file: " + je.getMessage());
        }

    }

This is the sample of my JSON file:

[{
  "title": "CARE Deutschland-Luxemburg e.V.",
  "keyword": "CARE",
  "description": "<p><b>Das CARE-Komplett-Paket für Menschen in Not</b></p><p>Schnell, nachhaltig und durchdacht, das ist das moderne CARE-Paket. CARE ist überzeugt, dass umfassende Hilfe von drei Seiten notwendig ist, um die weltweite Armut Schritt für Schritt zu verringern. Deswegen hat CARE sich seit seiner Gründung 1945 und dem Abwurf der ersten CARE-Pakete über Berlin weiter entwickelt. Heute steckt im CARE-Paket weit mehr als Zucker und Mehl. Heute bietet die Organisation in 70 der ärmsten Länder der Welt ein Komplett-Paket für Menschen in Not.</p><p><b>Das Komplett-Paket für Menschen in Not enthält:</b></p>*sofortige Nothilfe nach Katastrophen<br><br>*langfristige Entwicklungszusammenarbeit<br><br>*Schutz der Menschenrechte<br><br>",
  "smallImageUrl": "http://cdn.spendino.de/web/img/projects/home/1284113658.jpg",
  "bigImageUrl":"http://cdn.spendino.de/web/img/projects/small/1284113658.jpg",
  "cost": "5"
  },
  {
  "title": "Brot für die Welt",
  "keyword": "BROT",
  "description": "<p>„Brot für die Welt“ unterstützt unter der Maßgabe 'Helfen, wo die Not am größten ist' ausgewählte Projekte weltweit.</p><p>Von Angola bis Tansania, von der Förderung von Mahlzeiten bis zur gesundheitlichen Grundversorgung und Katastrophenhilfe.</p><p>Bei ihrem täglichen Kampf gegen Krankheiten, Hunger, Ungerechtigkeiten und Armut wird die Aktion „Brot für die Welt“ von der evangelischen Kirche unterstützt.</p><p>Die Aktion hat es sich zum Ziel gesetzt, die Entwicklungszusammenarbeit auf der ganzen Welt zu fördern und Hilfe zur Selbsthilfe zu leisten.</p>",
  "smallImageUrl": "http://cdn.spendino.de/web/img/projects/home/1267454286.jpg",
  "bigImageUrl":"http://cdn.spendino.de/web/img/projects/small/1267454286.jpg",
  "cost": "5"
  }]
  • 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-05-21T03:11:29+00:00Added an answer on May 21, 2026 at 3:11 am

    This simple code from JavaCodeGeeks will parse a JSON beautifully (see below). As for specifically why your code is not working I do not know.

    public class JsonParsingActivity extends Activity {
    
        String url = "http://search.twitter.com/search.json?q=javacodegeeks";
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            InputStream source = retrieveStream(url);
    
            Gson gson = new Gson();
    
            Reader reader = new InputStreamReader(source);
    
            SearchResponse response = gson.fromJson(reader, SearchResponse.class);
    
            Toast.makeText(this, response.query, Toast.LENGTH_SHORT).show();
    
            List<Result> results = response.results;
    
            for (Result result : results) {
                Toast.makeText(this, result.fromUser, Toast.LENGTH_SHORT).show();
            }
    
        }
    
        private InputStream retrieveStream(String url) {
    
            DefaultHttpClient client = new DefaultHttpClient(); 
    
            HttpGet getRequest = new HttpGet(url);
    
            try {
    
               HttpResponse getResponse = client.execute(getRequest);
               final int statusCode = getResponse.getStatusLine().getStatusCode();
    
               if (statusCode != HttpStatus.SC_OK) { 
                  Log.w(getClass().getSimpleName(), 
                      "Error " + statusCode + " for URL " + url); 
                  return null;
               }
    
               HttpEntity getResponseEntity = getResponse.getEntity();
               return getResponseEntity.getContent();
    
            } 
            catch (IOException e) {
               getRequest.abort();
               Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
            }
    
            return null;
    
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?

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.