【问题标题】:JSON Unicode httpequestJSON Unicode http请求
【发布时间】:2014-04-27 08:11:53
【问题描述】:

我想制作 Unicode httprequest,尽管我将我的字符串更改为 Unicode,但有一些“??????”而不是我的 SQL 数据库中的我的应用程序名称。 (我的应用名称是波斯语)

 List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("dev_name", G.give_device_model()));
            params.add(new BasicNameValuePair("dev_ID", G.give_device_ID()));
            params.add(new BasicNameValuePair("follow_code", inputActivation.getText().toString()));
            params.add(new BasicNameValuePair("app_name",convert_2_unicode(msg) ));


            JSONObject json = jsonParser.makeHttpRequest(ur_register_app, "POST", params);

这是我转换为 Unicode 的函数:

  public String convert_2_unicode(String str){

        String string = "";
        try {
            // Convert from Unicode to UTF-8

            byte[] utf8 = str.getBytes("UTF-8");

            // Convert from UTF-8 to Unicode
            string = new String(utf8, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }

        return string;
    }

如何发送正确的 Unicode 请求?

【问题讨论】:

    标签: android json http unicode request


    【解决方案1】:

    终于解决了 在我使用的 JSON 解析器中:

    httpPost.setEntity(new UrlEncodedFormEntity(paramsHTTP.UTF_8));
    

    代替:

    httpPost.setEntity(new UrlEncodedFormEntity(params ));
    

    【讨论】:

      【解决方案2】:

      可能是您的数据库或表上设置了不正确的排序规则。

      https://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html

      您可以使用 phpMyAdmin 进行检查。

      【讨论】:

      • 我的数据库排序规则没问题,因为当我从 URL 传递参数时,它们保存在 unicode 中。
      • 我猜这取决于你提出请求的方式。
      猜你喜欢
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 2011-05-27
      • 2014-12-14
      相关资源
      最近更新 更多