如何将ArrayList编码为utf-8

时间:2016-10-23 13:16:26

标签: java android json arraylist

问题在于我发送了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");
}

0 个答案:

没有答案