我是从api上获得的... img src = \“ http://www.smartguides.in/wp-content/uploads/2019/07/surgeons-operating-on- Patient-493216377-577a3d1a5f9b585875330ddc.jpg \” alt = \“ \” data-id = \“ 259 \”数据链接= \“ http://www.smartguides.in/?attachment_id = 259 \” class = \“ wp-image-259 \” /
我只需要img src值,这就是为什么我使用下面的代码。
try {
JSONArray jsonArray = new JSONArray(response);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject=new JSONObject(jsonArray.getString(i));
JSONArray jsonArray1=jsonObject.optJSONArray("post_content_images");
if (jsonArray1!=null){
for (int j=0;j<jsonArray1.length();j++){
JSONArray jsonArray2=jsonArray1.optJSONArray(j);
for (int z=0;z<jsonArray2.length();z++){
String fv=jsonArray2.optString(z);
String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
Pattern p = Pattern.compile(imgRegex);
Matcher m = p.matcher(fv);
if (m.find()) {
String imgSrc = m.group(1);
Toast.makeText(getApplicationContext(),""+imgsrc,Toast.LENGTH_LONG).show();
}}}}}} catch (JSONException e) {e.printStackTrace();}}
吐司味精显示适当的结果。但是当我将其存储在arraylist中时,它返回空值... 对我有什么建议。.plz