将图释转换为unicode

用户名

我需要将包含文本和表情符号的文本发送到服务器。我使用jsonparser类将其发送到服务器。但是当我发送它时,服务器端似乎包含unicode的问号。我应该如何继续转换为unicode。请帮忙。

    List<NameValuePair> params = new ArrayList<NameValuePair>();

         Log.d("userstatus",userstatus);

        params.add(new BasicNameValuePair("my_status",userstatus));
         params.add(new BasicNameValuePair("user_id",userid));



          try{
              // getting JSON string from URL
               JSONObject json3 = jParser.makeHttpRequest(url_updateprofilestatus, "POST", params);

                 Log.d("json response: ", json3.toString());
                 JSONObject response=json3.getJSONObject("response"); 

我的JSONParser类

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

// function get json from url
// by making HTTP POST or GET mehtod
public JSONObject makeHttpRequest(String url, String method,
        List<NameValuePair> params) {

    // Making HTTP request
    try {

        // check for request method
        if(method == "POST"){
            // request method is POST
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

        }else if(method == "GET"){
            // request method is GET
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
        }          

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        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();
        json = sb.toString();

    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}

}

我收到带有文字和“?”的回复 表情符号。请帮忙。

用户名

我得到了答案。要获取表情符号的unicode,请执行以下操作:

StringEscapeUtils.escapeJava(<text>); 

并将其解码回图释:

StringEscapeUtils.unescapeJava(<unicode_emoticon>);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章