Solorchid Solorchid - 1 year ago 93
Android Question

Java/Android how to get JSON from a html response?

I'm getting an html response from HttpGet,the response is like following:

<div class="noti-contents">
<button class="accept-invitation gui-button" data-invite="pi:103158:18:60:114779" data-invite-details='{"f":"103158","p":18,"api":false,"pid":60,"t":114779,"sub":"p10315857a3f8","u":{"id":"103158","name":"xxxxxx","profile_image":"{1}","status":"1"}}'><span>Accept</span></button>

and all the above code are stored in a string variable 'response'; but now in my app i only need the JSON part of the html:


so how should I parse this string to get the only the above part?

Answer Source

Have a look at the docs

You can use Jsoup to parse html

Document doc = Jsoup.parse("html string");  
Elements elements ="button");


08-15 19:16:42.670: I/..........(1612): {"f":"103158","p":18,"api":false,"pid":60,"t":114779,"sub":"p10315857a3f8","u":{"id":"103158","name":"xxxxxx","profile_image":"{1}","status":"1"}}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download