Finding Difficulties in extracting html_instructions from Direction API JSON data for Android in Eclipse

StackOverflow https://stackoverflow.com/questions/19450988

I am retrieving data from Google Direction API in the JSON format from which i am able to retrieve data. But one of the data is using escape sequences.

"end_location" : {
                              "lat" : 40.6497695,
                              "lng" : -73.94947789999999
                           },
                           "html_instructions" : "Head \u003cb\u003eeast\u003c/b\u003e on \u003cb\u003eErasmus St\u003c/b\u003e toward \u003cb\u003eNostrand Ave\u003c/b\u003e",
                           "polyline" : {
                              "points" : "}kbwFjjjbMAq@?SAK?Q"
                           },

now the problem is that html_instructions is forming data like a HTML (with escape sequence). But i want to display this data in a ListView Control. So i need to retrieve those instructions but without HTML part (if it make that thing bold i don't mind but i don't want it to be shown as Head toward...).

So how can i extract the data in my desired format.

有帮助吗?

解决方案

If you are using the text from JSON in a TextView then you can use this method to show it correctly.

Say, JSONObject from "end_location" is named Object in your code. Then,

String instruction = Object.getString("html_instructions");
YourTextView.setText(Html.fromHtml(instruction));

It will show html formatted string in your TextView. Hope it helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top