问题在于我发送了JSON
。在DB而不是Cyrillic,问号。
我在做:
ArrayList<String> arrayList = new ArrayList<>();
arraylist.add("first");
arraylist.add("second");
arraylist.add("third");
arraylist.add("fourth");
然后我将ArrayList
转换为Json
String jsonString = new Gson().toJson(arrayList);
发送:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Application.TEST_API);
List<NameValuePair> valuePairs = new ArrayList<>();
valuePairs.add(new BasicNameValuePair("request", "SAVE_RESULT"));
valuePairs.add(new BasicNameValuePair("result", jsonString));
httppost.setEntity(new UrlEncodedFormEntity(valuePairs));
HttpResponse httpResponse = httpclient.execute(httppost);
问题:
1)如何在jsonString
中转换为UTF-8
我的数组?
2)或发送问题where httppost.setEntity (new UrlEncodedFormEntity (valuePairs))
,自UrlEncodedFormEntity ()
public UrlEncodedFormEntity(List<? extends NameValuePair> parameters) throws UnsupportedEncodingException {
this(parameters, "ISO-8859-1");
}