我们在实际的开发中会有这样的json串:
{"code":200,"message":"请求成功~","data":{"url":"8001url://127.0.0.1/dept/get3/id/sjahgdajkdhaskjd/@askjdhj@sakjdhasjk"}}
转成JavaBean更好的操作,直接上高速(手敲不易--欢迎打赏)
安装插件:
建一个class --TestUrlVo -- 右键--看到GsonXXX next。。。
@Test
public void test012(){
String s = HttpUtil.get("http://127.0.0.1:8001/dept/get3/1");
System.out.println(s);
System.out.println("-------------------------");
TestUrlVo testUrlVo = JSON.parseObject(s, TestUrlVo.class);
TestUrlVo.DataVo data = testUrlVo.getData();
System.out.println(data.getUrl());
}
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.12</version>
</dependency>