2013-05-07 89 views
1

我在開發的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) 
+0

您是通過HTTP發送此郵件? – sanbhat 2013-05-07 14:11:15

+0

是的。 「BaseUrl」字符串設置爲http:// ....如果這就是你的意思。 – localhost 2013-05-07 14:27:27

+0

我想檢查您是否通過HTTP協議傳輸Hashtable並且看起來像是這樣的情況下,所有內容都將被編碼 – sanbhat 2013-05-07 14:30:48

回答

1

您可以使用java.net.URLDecoder解碼編碼文本

URLDecoder.decode("%3FTYPE%3DleagueSearch%26JSON%3D1=%26SEARCH%3Dtest", "UTF-8") 

會產生

?TYPE=leagueSearch&JSON=1=&SEARCH=test 
+0

謝謝!這應該是對的。我試圖補充說,但沒有改變。將它更改爲以下內容後,我仍然得到相同的輸出結果:http://pastie.org/7813425。有什麼建議麼? – localhost 2013-05-07 14:59:30

+0

這真的只在字符串被使用後纔有用。我需要一種方法來解碼編碼文本,然後將其放入字符串中。 – localhost 2013-05-07 15:42:33