Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Android Java UTF-8 JSON

One part of my app performs a query (via php) on a mysql database. I use in the database UTF-8 because I have letters like é à ê that need to appear. I read through this problem because this seemed almost the same.

Android Java UTF-8 HttpClient Problem

However when I am implementing the code he replaces every return value with an é as null.

This is my code

HttpParams params = new BasicHttpParams();
 HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
 HttpProtocolParams.setContentCharset(params, "UTF-8");
 params.setBooleanParameter("http.protocol.expect-continue", false);
 HttpClient httpclient = new DefaultHttpClient(params);
 HttpPost httppost = new HttpPost("http://www.example.com/example.php");
 httppost.setEntity(new UrlEncodedFormEntity(query));
 HttpResponse response = httpclient.execute(httppost);
 HttpEntity entity = response.getEntity();
 String jsonText = EntityUtils.toString(entity, HTTP.UTF_8);
 Toast.makeText(StoresInfo.this, jsonText, Toast.LENGTH_LONG).show();
 is = entity.getContent();

So in the jsonText string he replaces return values with a "è" in it by null.

The last line is = entity.getConent(); I added this because I normally use the input stream to read it but this does not work as well.

Somebody has an idea?

This is my php code

<?php
 mysql_select_db("database");
 $q=mysql_query($_REQUEST['query']);
 while($e=mysql_fetch_assoc($q))
 $output[]=$e;
 print(json_encode($output));
 mysql_close();
 ?>

Answer*

Draft saved
Draft discarded
Cancel
1
  • Hi mate! This actually did the trick! I wrote everything in a comma separted file in notepad and uploaded it! Now i see the accents! Thank you very very much! Commented Mar 16, 2011 at 17:12

default

AltStyle によって変換されたページ (->オリジナル) /