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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:05:00+00:00 2026-05-27T11:05:00+00:00

I have a problem with parsing my JSon Data in an Android application. I

  • 0

I have a problem with parsing my JSon Data in an Android application. I use a PHP script to get the Data from mysql and put it in a JSON. The problem is I can print the result and I see all the items that are in my table people.

JSON data from database

but when the data is passed to the stringbuilder everything goes wrong. Afther parsing JSON’s array say’s that there is only one object in my Array?
I hope you can help me or give me some advice.

try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://10.0.1.10/getAllPeople.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();
       sb.append(reader.readLine() + "\n");
       String line="0";
       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
int id;
double Lat;
double Long;
String hulp = "";

v3 = (TextView) findViewById(R.id.tv3);
//v3.setText("Resultaat: " + result);

try{
      jArray = new JSONArray(result);
      for(int i=0;i<jArray.length();i++){                 
             JSONObject json_data = jArray.getJSONObject(i);
             id = json_data.getInt("id");
             Long = json_data.getDouble("long");
             Lat = json_data.getDouble("lat");
             hulp = hulp + "\n" +  "Long: " + Long + " Lat: " + Lat;
             mob.add(new MobieleFlitsers(id,Long,Lat));
         }

      for(int i=0;i<mob.size();i++){

          hulp = " " + mob.size();
        }
        v3.setText(hulp);
      }
      catch(JSONException e1){
          Toast.makeText(getBaseContext(), "Geen locatie's gevonden" ,Toast.LENGTH_LONG).show();
      } catch (ParseException e1) {
            e1.printStackTrace();
    }

I have added the PHP code because it stores the wrong JSON format.

        $q=mysql_query("SELECT * FROM people");

    //while($e=mysql_fetch_assoc($q))
    //$output[]=$e;
    //print(json_encode($output));
    //mysql_close();

    if (!$q) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
    }

    if (mysql_num_rows($q) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }

    // While a row of data exists, put that row in $row as an associative array
    // Note: If you're expecting just one row, no need to use a loop
    // Note: If you put extract($row); inside the following loop, you'll
    //       then create $userid, $fullname, and $userstatus
    while ($row = mysql_fetch_row($q)) {
        $output[]=$row;
        print(json_encode($output));


    }
    mysql_close();
}

}

?>

  • 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-27T11:05:01+00:00Added an answer on May 27, 2026 at 11:05 am

    to complete jakeclarkson answer , in your PHP this

    while ($row = mysql_fetch_row($q)) {
        $output[]=$row;
        print(json_encode($output));
    }
    

    prints the entire json so far at each row, so basically, it print [1][1,2][1,2,3]… instead of only the last one. You simply need to extract your print after $output is complete:

    while ($row = mysql_fetch_row($q)) {
        $output[]=$row;
    }
    print(json_encode($output));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends i am having problem in parsing jSON web services data I have
A] Problem summary: I have JSON data being returned from python to javascript. I
I have a problem with parsing a JSON result. This is what I get
I have some problem with JSON parsing. When I hit URL, I've got JSON
I started getting errors in my browser, parsing JSON return data from the server.
Ok, I have a very frustrating problem. I am parsing a webpage and need
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem when I try insert some data to Informix TEXT column via
I have a jQuery ajax function that retrieves JSON data. In the success block
I'm having a problem with relationships between to entities in Core Data. I'm parsing

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.