I know it's an habitual question; but mine is really strange. I've done in another context exactly the same code where it works, but not on th
String result = "";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.145/test/getActivities.php");
//httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
//convert response to string
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
try{
JSONArray jArray = new JSONArray(result);
Log.e("log_tag", "lool");
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
if (json_data.getString("friendly_url").toString().length() == 2){
Sectors.add(new BasicNameValuePair(json_data.getString("title").toString(),json_data.getString("friendly_url").toString()));
}
else if(json_data.getString("friendly_url").toString().length() == 3){
Branchs.add(new BasicNameValuePair(json_data.getString("title").toString(),json_data.getString("friendly_url").toString()));
}
else if(json_data.getString("friendly_url").toString().length() == 4){
SBranches.add(new BasicNameValuePair(json_data.getString("title").toString(),json_data.getString("friendly_url").toString()));
}
else{
SBranches.add(new BasicNameValuePair(json_data.getString("title").toString(),json_data.getString("friendly_url").toString()));
}
String[] lesSec = new String[Sectors.size()];
for (int u = 0; u < Sectors.size(); u ++)
lesSec[u] = jArray.getJSONObject(u).getString("title");
setSectors(lesSec);
Log.e("log_tag", lesSec[1]);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
So this is the PHP file
<?php
$response = array();
$response["success"] = 0;
$response["message"] = "No products found";//*/
@mysql_connect("host","user","");
@mysql_select_db("db");
$q=@mysql_query("SELECT title, friendly_url FROM table");
while($e=@mysql_fetch_assoc($q))
$OUTPUT[]=$e;
print(json_encode($OUTPUT));
print_r ($OUTPUT);
@mysql_close();
?>
Can anyone see the problem? I tried to print the $OUTPUT and this is the kind of result
Array ( [0] => Array ( [title] => Activités de services autres et institutions
[friendly_url] => 15
)
[1] => Array ( [title] => Batiment, travau ...etc