Parsing "html_attributions" from a Google Places answer in JAVA

The policy must state "html_attributions" in the application. This answer was received as - "html_attributions": ["Lists on \ u003ca href = \" http: // Some websites .com / \ "\ u003esSome website \ u003c / a \ u003e"]

When I parse it as jObject.getJSONArray ("html_attributions"), I get - ["Listings by <a href=\"http:\/\/www.some website.com\/\">some website<\/a>"]

It cannot be displayed as is, as it does not match html. Is there a way to properly parse this attribution to extract a valid html string?

+4
source share
2 answers

Google Places Api Sample, .

formatPlaceDetails, . HTML- , .

private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id,
            CharSequence address, CharSequence phoneNumber, Uri websiteUri) {
        Log.e(TAG, res.getString(R.string.place_details, name, id, address, phoneNumber,
                websiteUri));
        return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber,
                websiteUri));

    }

string.xml

<string name="place_details">&lt;b&gt;%1$s&lt;/b&gt;&lt;br/&gt;&lt;i&gt;Place Id: %2$s&lt;/i&gt;&lt;br/&gt;Address: %3$s&lt;br/&gt;Phone: %4$s&lt;br/&gt;Website: %5$s</string>
+1

google . html, url, html, xml.

 This is an example of an attribution in JSON format:

"html_attributions" : [
      "Listings by \u003ca href=\"http://www.example.com/\"\u003eExample Company\u003c/a\u003e"
],

This is an attribution in XML format:
<html_attribution>Listings by <a href="http://www.example.com/">Example Company</a></html_attribution>
0

Source: https://habr.com/ru/post/1547688/


All Articles