当前位置:   article > 正文

Jsonpath使用

documentcontext.set jsonpath

Jsonpath使用

JsonPath使用入门

感兴趣的小伙伴可以加入QQ群:556029945

  1. {
  2. "store": {
  3. "book": [
  4. {
  5. "category": "reference",
  6. "author": "Nigel Rees",
  7. "title": "Sayings of the Century",
  8. "price": 8.95
  9. },
  10. {
  11. "category": "fiction",
  12. "author": "Evelyn Waugh",
  13. "title": "Sword of Honour",
  14. "price": 12.99
  15. },
  16. {
  17. "category": "fiction",
  18. "author": "Herman Melville",
  19. "title": "Moby Dick",
  20. "isbn": "0-553-21311-3",
  21. "price": 8.99
  22. },
  23. {
  24. "category": "fiction",
  25. "author": "J. R. R. Tolkien",
  26. "title": "The Lord of the Rings",
  27. "isbn": "0-395-19395-8",
  28. "price": 22.99
  29. }
  30. ],
  31. "bicycle": {
  32. "color": "red",
  33. "price": 19.95
  34. }
  35. },
  36. "expensive": 10
  37. }

简单使用

  1. @Test
  2. public void userJsonPath(){
  3. DocumentContext context = JsonPath.parse(json);
  4. Object read1 = context.read("$..book");
  5. System.out.println(read1);
  6. Object read2 = context.read("$..book[0].price");
  7. System.out.println(read2);
  8. context.set("$..book[0].price",10.00);
  9. Object read3 = context.read("$..book[0].price");
  10. System.out.println(read3);
  11. }

输出:

[[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"Herman Melville","title":"Moby Dick","isbn":"0-553-21311-3","price":8.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}]]
[8.95]
[10.00]

posted @ 2019-04-15 13:53 Sean_Deng 阅读(...) 评论(...) 编辑 收藏

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/977896
推荐阅读
相关标签
  

闽ICP备14008679号