Parsing "html_attributions" from Google Places response in JAVA
Asked Answered
A

2

6

Per policy it is mandatory show "html_attributions" in the app. This response is received as - "html_attributions" : [ "Listings by \u003ca href=\"http:// Some website.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>"]

This cannot be displayed as is since it is not html correct. Is there any method to parse this attribution correctly so that html valid string is extracted?

Aurelea answered 9/7, 2014 at 6:55 Comment(1)
have you found solution? I suggest it is in xml format so parse that html_attributions in xml parsing. which will give you link for thatPeshitta
T
1

Go through this Google Places Api Sample which describes a way of doing so.

It has a method formatPlaceDetails that Format details of the place for display. It does not support HTML tags directly, they need to be encoded first.

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>
Tropical answered 15/12, 2015 at 13:24 Comment(0)
P
0

It may help

From google I have found this on this page. Which is html tag and if we want exact url than we have to get from that html string parsed from 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>
Peshitta answered 15/12, 2015 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.