我在android中编写简单的应用程序,但是当我将带有JSON的阿拉伯字符发送到asp.net服务器页面时,在服务器中不知道阿拉伯字符,并告诉我这个:
["????"]
答案 0 :(得分:0)
对阿拉伯字符串进行编码,然后发送该字符串,
public static String getEncodedString(String str) {
String ret = null;
try {
ret = Base64.encode(str.getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
答案 1 :(得分:0)
public static String getEncodedString(String str) {
String myString= null;
try {
myString= new String(str.getBytes(), "ISO-8859-1");
} catch (Exception e) {
e.printStackTrace();
}
return myString;
}
答案 2 :(得分:0)
我的代码:
protected void onCreate(Bundle savedInstanceState)
{
countrynamemail=value.toString();
}
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
TextView mytext=(TextView)findViewById(R.id.textView);
TourMyCountry country=new TourMyCountry();
String base64=null;
try{
byte[] data = countrynamemail.getBytes("UTF-8");
base64= Base64.encodeToString(data, Base64.DEFAULT);
}catch (Exception e){
}
country.name= base64;
return POST(urls[0],country);
}
答案 3 :(得分:0)
protected void onCreate(Bundle savedInstanceState)
{
countrynamemail=value.toString();
}
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
TextView mytext=(TextView)findViewById(R.id.textView);
TourMyCountry country=new TourMyCountry();
String base64=null;
try{
byte[] data = countrynamemail.getBytes("UTF-8");
base64= Base64.encodeToString(data, Base64.DEFAULT);
}catch (Exception e){
}
country.name= base64;
return POST(urls[0],country);
}
protected void onPostExecute(String result) {
Toast.makeText(getBaseContext(), result, Toast.LENGTH_LONG).show();
//Log.d("My Return BackUp is:",result.toString());
ArrayList<String> itemsList=new ArrayList<String>();
try {
JSONArray jsonArray=new JSONArray(result);
for(int i=0;i<jsonArray.length();i++)
{
JSONObject JsonObj=jsonArray.getJSONObject(i);
String CityName=JsonObj.getString("toas");
itemsList.add(CityName);
}
ListView mylist=(ListView) findViewById(R.id.listView);
ArrayAdapter<String> myAdaptor = new ArrayAdapter<String>(tourdetail.this, android.R.layout.simple_list_item_1, itemsList);
mylist.setAdapter(myAdaptor);
} catch (JSONException e) {
e.printStackTrace();
}
}
答案 4 :(得分:0)
经过对我的同样问题的大量研究。我找到了解决方案。请检查并使用Charset将其更改为UTF-8设置。
sendEnquiryJson.put("comments", comments.getText().toString().trim());
Charset chars = Charset.forName("UTF-8");
StringBody eMail = new StringBody(sendEnquiryJson.toString(), chars);