Java/Android如何从html响应中获取JSON? [英] Java/Android how to get JSON from a html response?

查看:120
本文介绍了Java/Android如何从html响应中获取JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从HttpGet获得html响应,响应如下:

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>
</div>

和以上所有代码都存储在字符串变量"response"中;但现在在我的应用中,我只需要html的JSON部分:

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:

{"f":"103158","p":18,"api":false,"pid":60,"t":114779,"sub":"p10315857a3f8","u":{"id":"103158","name":"xxxxxx","profile_image":"{1}","status":"1"}}

那么我应该如何解析此字符串以获取仅上述部分?

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

推荐答案

看看文档

http://jsoup.org/apidocs/org/jsoup/Jsoup.html

您可以使用Jsoup解析html

You can use Jsoup to parse html

Document doc = Jsoup.parse("html string");  
Elements elements = doc.select("button");
Log.i("..........",""+elements.attr("data-invite-details"));

日志

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"}}

这篇关于Java/Android如何从html响应中获取JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆