向webservice发送和接收表情符号

时间:2014-11-11 10:49:04

标签: android web-services emoji

我已经为表情符号实现了https://github.com/ankushsachdeva/emojicon lib,并且在编辑文本中显示了表情符号。现在我编辑了包含文本和表情符号的文本。我希望将编辑文本中输入的文本/表情符号发送到Web服务。当我只是说从编辑文本中获取文本时我只能看到'??'服务器上的表情符号。我知道我必须将表情符号转换为Unicode然后发送它但我不知道如何实现它以及如何只解码编辑文本中的表情符号。请帮帮我。

我只是从编辑文本中获取文本并将其保存在'userstatus'字符串中并将其传递给json

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);

我的json课程

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;

}

}

2 个答案:

答案 0 :(得分:0)

表情符号只不过是特殊的文本序列,它指的是设备上的一些表情符号。在发送表情符号时,您实际上并不发送表情符号,而是发送与其相关联的文本字符序列。一旦设备收到它,它就会用正确的表情符号(图像)替换该特定文本。喜欢(^)相当于Skype中的蛋糕表情符号。

答案 1 :(得分:0)

我有同样的问题,通过添加POST方法解决了

确保在Logger中你得到带有黑色背景的问号,以确保它是一个表情符号

然后添加:

$gen_arr = array_fill_keys(array_column($arr, 'month'), array());
$final_arr = array(); // Array to store the result
foreach ($gen_arr as $gen_key => $gen_value) {
  foreach ($arr as $org_key => $org_value) {
    //temporarily store the original array
    $temp = $org_value;
    if ($gen_key != $temp['month'] && !in_array($temp['title'], $final_arr[$gen_key])) {
      $temp['month'] = $gen_key;
      $temp['count'] = 0;
    }

    $final_arr[$gen_key][] = $temp;
  }
}
return $final_arr;