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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:57:15+00:00 2026-06-10T00:57:15+00:00

While using the Rotten Tomatoes API I am getting the following error: org.json.JSONException: Value

  • 0

While using the Rotten Tomatoes API I am getting the following error:

org.json.JSONException: Value 596 of type java.lang.String cannot be converted to JSONArray.

I am attempting to parse out data from the Rotten Tomatoes API which is in JSON format.

Here is what my code looks like.

package com.my.apitest;

import java.io.*;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.json.*;
import org.apache.http.impl.client.*;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.EditText;

public class MainActivity extends Activity {

    EditText display;
    HttpResponse responseGet;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            display = (EditText) findViewById(R.id.textBox);

            String result = "";

            try {
            HttpClient client = new DefaultHttpClient();
            String movieID = "770672123";

            HttpPost getCast = new HttpPost("http://api.rottentomatoes.com/api/public/v1.0/movies/" +
                                            movieID + "/cast.json?apikey=3p9ehnhzbxwpbd6mk8fncf67");

            HttpResponse responseGet = client.execute(getCast);
            HttpEntity resEntityGet = responseGet.getEntity();

            InputStream webs = resEntityGet.getContent();

            // (i was converting to string like this)display.setText(EntityUtils.toString(resEntityGet));

            try{
                BufferedReader reader = new BufferedReader (new InputStreamReader (webs, "iso-8859-1"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                webs.close();
                result=sb.toString();
            }catch(Exception e 
                Log.e("log_tag", "Error converting result: " + e.toString());

            }
        }catch(Exception e 
            Log.e("log_tag", "Error in http connection " + e.toString());
        }

        try{
            JSONArray jArray = new JSONArray(result);

            for (int i=0; i<jArray.length(); i++ 
                JSONObject json_data = jArray.getJSONObject(i);
                display.setText(json_data.getString("name"));
            }
        }
        catch(JSONException e 
            Log.e("log_tag", "Error parsing data " + e.toString());
        }
    }   
    catch (Exception e 
        Log.e("Error", "Error in Code:" + e.toString());
        e.printStackTrace();}
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return false;
    }
}

After doing some digging I have come across some information suggestion I need to connect to the api with PHP. I am new to APIs and mobile development so I am not sure how to go about that or if that is in fact the issue. I think what may be happening is the error is being raised due to the absence of a PHP file to connect to the API and decode the JSON. Does that sound right? Any help would be greatly appreciated.

  • 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-10T00:57:16+00:00Added an answer on June 10, 2026 at 12:57 am

    If your response start with [ Square brecket than it indicate JSONArray than you have to use

    JSONArray  jsonarray=new JSONArray(response);
    

    and if it is start with { Curly bracket than it indicate JSONObject than you have to use

    JSONObject jsonobject=new JSONObject(response);
    

    see more details about json at http://www.json.org/ and example for JSON parsing in android

    Android JSONParsing Tutorial 1

    Android JSONParsing Tutorial 2

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

Sidebar

Related Questions

while using tiles along with spring i m getting following error: java.net.UnknownHostException: tiles.apache.org program
While using sqlcipher in Android 2.3.3. I am getting error. Here is my DB.java
While using inner join on Pro*C I am getting the below error: PCC-S-02201, Encountered
While using a third party dll I was getting the following exception: exePath must
While using VariantCopy method, I come across the following compile error: error C2664: 'VariantCopy'
while using the following constructor $this->pdo = new PDO ($this->source, $this->username, $this->password); if I
while using document cookie <script typ=text/javascript> document.domain=example.com; </script> I got an error.i don't know
While using Java's switch case, it excepts only char and int, but I want
While using texture memory I have come across the following code:- uint f =
While using the Nimbus L&F feel in Java, I am having problems with changing

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.