用正则解析JSON

来源:互联网 发布:linux windows samba 编辑:程序博客网 时间:2024/05/18 20:08
 private void getData(String str){
apptxt="";
ImgList=new ArrayList<String>();
newsList=new ArrayList<News>();
String s=str.replace("...", ""); 
str=s;
int i=1;
Pattern pattern = Pattern.compile("\\{\"link\":\"(.+?)\",\"title\":\"(.+?)\",\"image\":\"(|.+?)\",\"brief\":\"(|.+?)\",\"content\":\"(|.+?)\",\"time\":\"(|.+?)\",\"n_read\":(|.+?),\"n_like\":(.+?)\\}");     
Matcher matcher = pattern.matcher(str); 
//str="";
boolean ist=false;
while (matcher.find()) { 
news=new News();
news.setlink(matcher.group(1));
news.setTitle(matcher.group(2));
news.setContent(matcher.group(3));
news.setContent(matcher.group(5));
news.settxt(matcher.group(5));
newsList.add(news);
ImgList.add(matcher.group(3));
ist=true;


}

if(caxun("appset","saveis")==null){
insert("appset","saveis","no");
}



if(ist==true && caxun("apititle",appurl)==null && gis(caxun("appset","saveis"),"ye")){
insert("apititle",appurl,str);
dog("已自动保存数据");
dog();
}
if(ist==true && gis(caxun("appset","saveis"),"no")){
apptxt=str;
}
adapter=new NewsAdapter(MainActivity.this, newsList, ImgList);
ScaleInAnimationAdapter scaleInAnimationAdapter = new ScaleInAnimationAdapter(adapter, 0f);
scaleInAnimationAdapter.setListView(listView);
listView.setAdapter(scaleInAnimationAdapter);
}
0 0
原创粉丝点击