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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:17:09+00:00 2026-06-10T15:17:09+00:00

I read data from a database (only the last row, I do it in

  • 0

I read data from a database (only the last row, I do it in my php file) what I want to do is to use the data of each field separately but the problem is that the JSONArray is empty I tried a lot of ways to do it looking for it in different posts but it´s always empty.

This is my code

public class MainActivity extends Activity {
    /** Called when the activity is first created. */

    JSONArray jArray = null;
    String result = null;
    InputStream is = null;
    StringBuilder sb=null;

    String ct_id;
    String ct_name;

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

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
      //http post
        try{
            HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost= new HttpPost("http://xxx.php");


            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

         }catch(Exception e){
            Log.e("log_tag", "Error in http connection"+e.toString());
         }
      //convert response to string
        try{
              BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
               sb = new StringBuilder();


               String line=null;
               while ((line = reader.readLine()) != null) {
                              sb.append(line + "\n");
                }
                is.close();
                result=sb.toString();
                }catch(Exception e){
                      Log.e("log_tag", "Error converting result "+e.toString());
                }
        //paring data

        try{
              jArray = new JSONArray(result);
              JSONObject json_data=null;
              for(int i=0;i<jArray.length();i++){
                     json_data = jArray.getJSONObject(i);
                     ct_id=json_data.getString("fecha");
                     ct_name=json_data.getString("dia");
                 }
              }
              catch(JSONException e1){
                  Toast.makeText(getBaseContext(), "JSON is empty" ,Toast.LENGTH_LONG).show();
              } catch (ParseException e1) {
                    e1.printStackTrace();
            }


    }
}

It always catchs JSONException e1.

Thank you everibody in advance

  • 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-10T15:17:11+00:00Added an answer on June 10, 2026 at 3:17 pm

    The problem was in PHP file, JSON couldn´t understand the data and that is why it was empty, I changed it and now works properly.

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

Sidebar

Related Questions

I read data from a mysql database that has is filled by php scripts.
I need to read data from a legacy database file produced by Visual Basic
I'm making chat application and read messages data from SQLite database. I want to
currently I use DataSet to read data from ADO.NET SQL provider, but I read
I want to read (only) records from data/data/com.android.providers.telephony/databases/mmssms.db (I know no official API, etc.
I have the following problem. I want to read data from a Database in
I am reading data from remote oracle database with read only access . and
I'm trying to find how to read data from my database in my iphone
When we define a record set in VBA & read the data from database,
i try to read Data from an Oracle-Database. The problem is that in some

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.