Java/Android如何从html响应中获取JSON?

编程入门 行业动态 更新时间:2024-10-06 01:45:23
本文介绍了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?

推荐答案

看看文档

jsoup/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?

本文发布于:2023-11-26 23:12:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   Java   JSON   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!