防止将散列表转换为ASCII
问题描述:
我在开发的Android应用程序中运行散列表。当我运行该活动时,它将“ht”的内容转换为ASCII字符。有谁知道一种方法来防止这种情况发生?防止将散列表转换为ASCII
基本上,我需要解码编码的文本,并在字符串中使用结果。为了工作,字符串中使用的URL不能包含编码文本。
Hashtable的
@SuppressWarnings("unchecked")
private void executeAsyncTask(){
Hashtable<String,String> ht=new Hashtable<String,String>();
GetDeptAyncTask async=new GetDeptAyncTask();
ht.put("?TYPE=leagueSearch&JSON=1","&SEARCH=test");
try {
URLDecoder.decode(""+ht, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@SuppressWarnings("rawtypes")
Hashtable[] ht_array={ht};
async.execute(ht_array);
}
试图在字符串中使用它
protected String doInBackground(Hashtable<String,String>... params) {
@SuppressWarnings("rawtypes")
Hashtable ht=params[0];
@SuppressWarnings("unchecked")
String json=HelperHttp.getJSONResponseFromURL(BaseUrl+"2013/export", ht);
如何 “HT” 中的 “JSON” 读字符串
?%3FTYPE%3DleagueSearch%26JSON%3D1=%26SEARCH%test
如何URL应当被读取
?TYPE=leagueSearch&JSON=1&SEARCH=test
logcat的为 “HT”
?:??: W/?(?): Hashtable {?TYPE=leagueSearch&JSON=1=&SEARCH=test}
logcat的为 “json的” 串
?:??: W/?(?): URL==>HIDDENURL/export?%3FTYPE%3DleagueSearch%26JSON%3D1=%26SEARCH%test
?:??: W/?(?): Json Response==><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">....
?:??: W/?(?): at org.json.JSONObject.<init>(JSONObject.java:127)
?:??: W/?(?): at myapp.app.MainActivity$GetDeptAyncTask.parseJsonString(MainActivity.java:80)
答
您可以使用java.net.URLDecoder
解码编码文本
URLDecoder.decode("%3FTYPE%3DleagueSearch%26JSON%3D1=%26SEARCH%3Dtest", "UTF-8")
会产生
?TYPE=leagueSearch&JSON=1=&SEARCH=test
您是通过HTTP发送此邮件? – sanbhat 2013-05-07 14:11:15
是的。 “BaseUrl”字符串设置为http:// ....如果这就是你的意思。 – localhost 2013-05-07 14:27:27
我想检查您是否通过HTTP协议传输Hashtable并且看起来像是这样的情况下,所有内容都将被编码 – sanbhat 2013-05-07 14:30:48