求节点里面的数据

jgszhuzhu 2013-01-21 04:53:26
数据如下
"base":"<a href=\"\/?r=search\/index\/index&searchType=shop&cat_code=&searchText=%E7%81%AB%E9%94%85\" target=\"_blank\">\u706b\u9505<\/a> <a href=\"\/?r=search\/index\/index&searchType=shop&cat_code=&searchText=ktv\" target=\"_blank\">KTV<\/a> <a href=\"\/?r=search\/index\/index&searchType=shop&cat_code=&searchText=%E5%A5%B3%E8%A3%85\" target=\"_blank\">\u5973\u88c5<\/a> <a href=\"\/?r=search\/index\/index&searchType=shop&cat_code=&searchText=%E7%BE%8E%E5%AE%B9\" target=\"_blank\">\u7f8e\u5bb9<\/a> <a href=\"\/?r=search\/index\/index&searchType=shop&cat_code=&searchText=%E7%94%B5%E5%99%A8\" target=\"_blank\">\u7535\u5668<\/a>

现要求取出<a *****>要取出的内容</a>
就是节点之间的内容里面第二个的KTV

之前取出了searchText后面的内容发现有的是乱码的,所以还是重新取节点的内容
老代码贴出来
JSONObject object = new JSONObject(content);

String string = object.getString("base");
Pattern pattern = Pattern.compile("searchText=([^\"]+)");
Matcher matcher = pattern.matcher(string);

while (matcher.find()) {
String wString = matcher.group().substring(11,
matcher.group().length());
...全文
276 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jgszhuzhu 2013-01-22
  • 打赏
  • 举报
回复
自己还是研究了一下正则写出来了
jgszhuzhu 2013-01-22
  • 打赏
  • 举报
回复
JSONObject object = new JSONObject(content); String string = object.getString("base"); Pattern pattern = Pattern.compile("blank\">([^</a]+)"); Matcher matcher = pattern.matcher(string); while (matcher.find()) { String wString = matcher.group().substring(7, matcher.group().length());
xq48799220 2013-01-21
  • 打赏
  • 举报
回复
那就完事了。。。 代码自己写吧。。。 也就几行而已。。 最多不超过20行。。
jgszhuzhu 2013-01-21
  • 打赏
  • 举报
回复
是直接丢掉的
xq48799220 2013-01-21
  • 打赏
  • 举报
回复
你的需求并没有说要取<a 里面的数据。直接丢掉就行了。
jgszhuzhu 2013-01-21
  • 打赏
  • 举报
回复
以 <a 开始, >里面的数据也不同
xq48799220 2013-01-21
  • 打赏
  • 举报
回复
最最简单的 截串吧。。。 以 <a 开始, >当作截取标志 <\/a>结束当作一个循环。。 还不会我也没办法。。。
jgszhuzhu 2013-01-21
  • 打赏
  • 举报
回复
写下代码哈 ,我自己也知道这样搞啊 ,关键是不会写
xq48799220 2013-01-21
  • 打赏
  • 举报
回复
有难度吗? 2种方法,一种是正则,一个是自己截串。 从<a 到 > 结束 开始取值 取到<\/a> 前面结束。 \u5973\u88c5 这样的数据自己转下就变成中文了。 拿到数据,该干什么干什么去。。。 代码就不写了。。。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧