我完成了我的应用程序的英文版本,目前正在处理我的阿拉伯语应用程序版本。虽然我的英文网络服务工作正常,但我的阿拉伯语网络服务似乎有问题,我觉得在使用JSONStringer类构造我的JSON请求时需要指定编码类型(utf-8)。有没有办法做到这一点?
以下是构造我的JSON请求的方法示例
public static String initLoginJSONRequest(String username, String password){
String parentString = null;
String childString = null;
try{
childString = new JSONStringer()
.object()
.key("username").value(username)
.key("password").value(password)
.endObject()
.toString();
parentString = new JSONStringer()
.object()
.key("UserCredentials").value(childString)
.endObject()
.toString();
}catch(JSONException e){
e.printStackTrace();
}
return parentString;
}
修改
我还要补充一点,我在HttpPost中指定我的编码是utf-8,如下所示,
HttpPost post = new HttpPost(getUrl);
StringEntity se = new StringEntity(jsonString);
se.setContentType("application/json;charset=UTF-8");//text/plain;charset=UTF-8
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
post.setEntity(se);
response = client.execute(post);
但它没有正确收到我在网络服务端(用.NET编写)的阿拉伯语字符。