json解析-----超简单的工具
2018-02-02 17:17
225 查看
使用webmagic爬虫的时候,有时候返回的数据是json字符串,就需要对其进行解析,其中自带的工具类JsonPathSelector很强大。笔记走一波
maven包
使用范例
结果展示
4000
maven包
<dependency> <groupId>us.codecraft</groupId> <artifactId>webmagic-core</artifactId> <version>0.7.3</version> </dependency>
使用范例
import java.util.List; import us.codecraft.webmagic.selector.JsonPathSelector; public class JsonSelect { public static void main(String[] args) { //json字符串 String jsonStr = "{\"head\": [ {\"text\":\"广州\",\"id\":\"广州\",\"pid\":\"广东省\"}, {\"text\":\"郑州\",\"id\":\"郑州\",\"pid\":\"河南省\"}] } "; //字符串转json // JSONObject json = JSONObject.parseObject(jsonStr); //json解析获得所有text List<String> id = new JsonPathSelector("$.head[*].text").selectList(jsonStr); //获取郑州 String city = new JsonPathSelector("$.head[1].text").select(jsonStr); // System.out.println(id.toString()); System.out.println(city); } }
结果展示
4000
相关文章推荐
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- 在www.json.org上公布了很多Java下的json解析工具,其中org.json和json-lib比较简单,两者使用上差不多
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- JSON解析工具——fastjson的简单使用
- 简单的json解析工具
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- JSON解析工具——Jackson的简单使用
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- Json解析工具Jackson(简单应用)
- Rapidjson的简单使用(拼接json串,存取文件中的json,解析json串)
- 利用Gson实现简单的json字符串解析
- Rapidjson的简单使用(拼接json串,存取文件中的json,解析json串)
- 关于fastjson解析对象和json串互转时空属性值不显示,简单mark一下