2012-08-07 27 views
0

我想在this鏈接從「步驟」陣解析「html_instructions」字符串:如何解析和格式化Google Directions JSON?

我沒有問題解析字符串,但它在混合碼位返回例如,分析的字符串的:

"html_instructions" : "Head \u003cb\u003esouthwest\u003c/b\u003e toward \u003cb\u003eCapitol Square SW\u003c/b\u003e", 

顯示爲:

Head southwest towards... 

Head<br>southwest"</br>"towards<br>... 

而不是簡單地表現爲中

有沒有一種方法,我可以格式化字符串以刪除「休息」?任何幫助是極大的讚賞。

回答

4

您可以使用正則表達式從您的內容中刪除HTML標籤。

String htmlString = "Head<br>southwest</br>towards<br>..."; 
    String noHtml = htmlString.replaceAll("<[^>]*>", ""); 
+0

工程就像一個魅力。謝謝。 – 2012-08-07 06:20:14

0

查看此問題的答案。

How to convert unicode in JavaScript?

基本上響應是以Unicode,因此<由\ u003c &表示>通過\ u003e可以使用字符串操作與適當的承租人替換這些字符串。

嘗試做這樣的事情

String parseResponse = response.replaceAll("\u003c","<"); 

這將讓你在正確的HTML格式的字符串。

+0

如果您需要更換html斷點,您可以使用字符串替換方法而不是替換<您可以用空白字符替換它。 – 2012-08-07 05:27:48