{"codi":-10,"obj":"S'ha denegat la connexi\u00c3\u00b3! El vostre compte o b\u00c3\u00a9 ha sigut bloquejat o b\u00c3\u00a9 encara no l'heu activat."}
哪个好。但是一旦我将这个字符串转换成json,就会失去utf-8:
JSONObject json = new JSONObject(response);
json有这个值:
{"obj":"S'ha denegat la connexió! El vostre compte o bé ha sigut bloquejat o bé encara no l'heu activat.","codi":-10}
我只是不知道如何改变它。我尝试过使用:
JSONObject json = (JSONObject) new JSONTokener(response).nextValue();
有没有更好的json库? thnks
编辑这是我从服务器得到答案的方式:
public void executeRequest(HttpUriRequest request, String url) {
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse;
try {
httpResponse = client.execute(request);
responseCode = httpResponse.getStatusLine().getStatusCode();
message = httpResponse.getStatusLine().getReasonPhrase();
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
response = EntityUtils.toString(entity, HTTP.UTF_8);
Log.d("TEST", response);
//Toast.makeText(this, jsonText, Toast.LENGTH_LONG).show();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
// e.printStackTrace();
} catch (IOException e) {
client.getConnectionManager().shutdown();
// e.printStackTrace();
}
}
EDIT2:根据要求,我包括以下结果:
的System.out.println(Arrays.toString(EntityUtils.toByteArray(实体)));
[123,34,99,111,100,105,34,58,45,49,48,44,34,111,98,106,34,58,34,83,39,104,97, 32,100,101,110,101,103,97,116,32,108,97,32,99,111,110,110,101,120,105,92,117,48,48,99,51, 92,117,48,48,98,51,33,32,69,108,32,118,111,115,116,114,101,32,99,111,109,112,116,101,32, 111,32,98,92,117,48,48,99,51,92,117,48,48,97,57,32,104,97,32,115,105,103,117,116,32, 98,108,111,113,117,101,106,97,116,32,111,32,98,92,117,48,48,99,51,92,117,48,48,97,57, 32,101,110,99,97,114,97,32,110,111,32,108,39,104,101,117,32,97,99,116,105,118,97,116,46, 34,125]