当前位置: 代码迷 >> J2EE >> java中怎么用正则截取html中的某个json串,初学者勿入
  详细解决方案

java中怎么用正则截取html中的某个json串,初学者勿入

热度:61   发布时间:2016-04-17 23:00:11.0
java中如何用正则截取html中的某个json串,高手请进,菜鸟勿入
如题:有以下html内容,现在要用java正则截取里边的红色json串,如何截取?
   ..............................
  ..............................
  ..............................
  ..............................
  ..............................
 userid:"",
    userNumID:"",//这个才是真正的 userid
    encodeUserNumId:"",
    spaceUrl:"",
    hasUserName: ('' == '0'),
    bdstoken : '',
    thirdLogo :'0',// 第三方网站登录的logo,为空则不显示
    se:'',
    needIE:'1',
    jit:'',
    showHot:'',
    hasResult: '1',
    aspSID:'5f0eaa1a4b4d23fc',
    strategyType:"star"
    });
    app.setData('imgData', 
{
"queryEnc": "%E8%B5%B5%E4%B8%BD%E9%A2%96", 
    "displayNum": 469591, 
    "bdIsClustered": "1", 
    "listNum": 1000, 
    "bdFmtDispNum": "469591", 
    "bdSearchTime": "", 
    "isNeedAsyncRequest": 0, 
    "data": [{
            "thumbURL": "http://img1.imgtn.bdimg.com/it/u=3808284378,2514394289&fm=11&gp=0.jpg", 
            "middleURL": "http://img1.imgtn.bdimg.com/it/u=3808284378,2514394289&fm=11&gp=0.jpg", 
            "largeTnImageUrl": "", 
            "hasLarge": 0, 
            "hoverURL": "", 
            "pageNum": 0, 
            "objURL": "http://upload.ct.youth.cn/2015/0919/1442618994341.jpg", 
            "fromURL": "ippr_z2C$qAzdH3FAzdH3Fu7g_z&e3By57pi_z&e3BvgAzdH3Fda8cAzdH3Fal8lAzdH3Fd8dbmd8_z&e3Bfip4s", 
            "fromURLHost": "fun.youth.cn", 
            "currentIndex": "", 
            "width": 423, 
            "height": 541, 
            "type": "jpg",
            "filesize": "", 
            "bdSrcType": "11", 
            "di": "5247142600", 
            "is": "", 
            "bdSetImgNum": 0, 
            "bdImgnewsDate": "2015-09-19 19:24", 
            "fromPageTitle": "爆表不输28岁<strong>赵丽颖</strong>", 
            "bdSourceName": "", 
            "bdFromPageTitlePrefix": "", 
            "isAspDianjing": 0, 
            "token": "", 
            "imgType": "", 
            "cs": "3808284378,2514394289", 
            "os": "1441301448,4073865134", 
            "source_type": ""
        }]
}

]);
        app.init();
    app.run();
    });
    }();
!function(){    require.async(['common:widget/ui/monitorRequest/monitorRequest.js'],function(monitorRequest){
var userid = "";
var q = "%E8%B5%B5%E4%B8%BD%E9%A2%96";
var tn = "result";
var host = "http://imgstat.baidu.com/4.gif";
var hostSweb = "http://image.baidu.com/pv/pv2.gif";
    var rsw = "";
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
------解决思路----------------------
	String str="";
str +="   userid:\"\", ";
str +="      userNumID:\"\",//这个才是真正的 userid ";
str +="      encodeUserNumId:\"\", ";
str +="      spaceUrl:\"\", ";
str +="      hasUserName: ('' == '0'), ";
str +="      bdstoken : '', ";
str +="      thirdLogo :'0',// 第三方网站登录的logo,为空则不显示 ";
str +="      se:'', ";
str +="      needIE:'1', ";
str +="      jit:'', ";
str +="      showHot:'', ";
str +="      hasResult: '1', ";
str +="      aspSID:'5f0eaa1a4b4d23fc', ";
str +="      strategyType:\"star\" ";
str +="      }); ";
str +="      app.setData('imgData',  ";
str +="  { ";
str +="  \"queryEnc\": \"%E8%B5%B5%E4%B8%BD%E9%A2%96\",  ";
str +="      \"displayNum\": 469591,  ";
str +="      \"bdIsClustered\": \"1\",  ";
str +="      \"listNum\": 1000,  ";
str +="      \"bdFmtDispNum\": \"469591\",  ";
str +="      \"bdSearchTime\": \"\",  ";
str +="      \"isNeedAsyncRequest\": 0,  ";
str +="      \"data\": [{ ";
str +="              \"thumbURL\": \"http://img1.imgtn.bdimg.com/it/u=3808284378,2514394289&fm=11&gp=0.jpg\",  ";
str +="              \"middleURL\": \"http://img1.imgtn.bdimg.com/it/u=3808284378,2514394289&fm=11&gp=0.jpg\",  ";
str +="              \"largeTnImageUrl\": \"\",  ";
str +="              \"hasLarge\": 0,  ";
str +="              \"hoverURL\": \"\",  ";
str +="              \"pageNum\": 0,  ";
str +="              \"objURL\": \"http://upload.ct.youth.cn/2015/0919/1442618994341.jpg\",  ";
str +="              \"fromURL\": \"ippr_z2C$qAzdH3FAzdH3Fu7g_z&e3By57pi_z&e3BvgAzdH3Fda8cAzdH3Fal8lAzdH3Fd8dbmd8_z&e3Bfip4s\",  ";
str +="              \"fromURLHost\": \"fun.youth.cn\",  ";
str +="              \"currentIndex\": \"\",  ";
str +="              \"width\": 423,  ";
str +="              \"height\": 541,  ";
str +="              \"type\": \"jpg\", ";
str +="              \"filesize\": \"\",  ";
str +="              \"bdSrcType\": \"11\",  ";
str +="              \"di\": \"5247142600\",  ";
str +="              \"is\": \"\",  ";
str +="              \"bdSetImgNum\": 0,  ";
str +="              \"bdImgnewsDate\": \"2015-09-19 19:24\",  ";
str +="              \"fromPageTitle\": \"爆表不输28岁<strong>赵丽颖</strong>\",  ";
str +="              \"bdSourceName\": \"\",  ";
str +="              \"bdFromPageTitlePrefix\": \"\",  ";
str +="              \"isAspDianjing\": 0,  ";
str +="              \"token\": \"\",  ";
str +="              \"imgType\": \"\",  ";
str +="              \"cs\": \"3808284378,2514394289\",  ";
str +="              \"os\": \"1441301448,4073865134\",  ";
str +="              \"source_type\": \"\" ";
str +="          }] ";
str +="  } ";
str +="  ]); ";
str +="          app.init(); ";
str +="      app.run(); ";
str +="      }); ";
str +="      }(); ";


Matcher m= Pattern.compile("'imgData',(.*?)\\]\\)").matcher(str);
while(m.find()){System.err.println(m.group(1));}
  相关解决方案