我在json
数据中有一个参数叫做"内容"从中我想获取图片网址并动态显示ImageView
中的图片。
我已经尝试了Pattern
和Matcher
类,我正确地获得了第一个网址,但无法为多个图片网址制作逻辑。
内容如下:
"content":"<p style=\"text-align: justify;\">Huawei India has expanded the reach and availability of their online-only Honor smartphone series.<img class=\"aligncenter size-full wp-image-14114\" src=\"http:\/\/imageurl.jpg\"\/><p style=\"text-align: justify;\">Huawei India, along with it, has also confirmed that Honor smartphones will get the Android 6.0 Marshmallow updates with other devices in the upcoming year in the month of February.<\/p><img class=\"aligncenter size-full wp-image-14115\" src=\"http:\/\/second Image url.png\" \/>\n<p style=\"text-align: justify;\">The new update is likely to get Huawei Honor users to be excited, if you are a Honor smartphone user do share your feelings in the comment box below.<\/p>\n"
我得到的第一个图片网址如下:
String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
Pattern p = Pattern.compile(imgRegex);
Matcher m = p.matcher(posts.getExcerpt());
String src = "";
if (m.find()) {
src = m.group(1);
imgPost.setVisibility(View.VISIBLE);
Log.v("groupCount : ",""+m.groupCount());
//Toast.makeText(this,"pattern : "+src,Toast.LENGTH_LONG).show();
Picasso.with(this)
.load(""+src)
.error(R.drawable.ic_launcher)
.into(imgPost);
}
知道如何使用PatternMatcher
类或其他任何内容获取所有图片网址吗?
答案 0 :(得分:1)
在我看来,一旦你获得了json字符串HTML中的内容。 你可以使用JSoup来提取数据非常容易。
答案 1 :(得分:0)
您可以使用while( m.find()){ ... }
代替条件