当前位置: 首页 > news >正文

门户网站登录入口安卓aso优化

门户网站登录入口,安卓aso优化,游戏网游戏平台,wordpress播放本地视频场景 若依前后端分离版手把手教你本地搭建环境并运行项目: 若依前后端分离版手把手教你本地搭建环境并运行项目_前后端分离项目本地运行-CSDN博客 在上面搭建SpringBoot项目的基础上,并且在项目中引入fastjson、hutool等所需依赖后。 Jayway JsonPat…

场景

若依前后端分离版手把手教你本地搭建环境并运行项目:

若依前后端分离版手把手教你本地搭建环境并运行项目_前后端分离项目本地运行-CSDN博客

在上面搭建SpringBoot项目的基础上,并且在项目中引入fastjson、hutool等所需依赖后。

Jayway JsonPath:

GitHub - json-path/JsonPath: Java JsonPath implementation

A Java DSL for reading JSON documents

需要对接第三方接口,接口返回的json数据需要解析获取数据。

可以通过配置每个返回字段的对应json数据的表达式,使其在代码中根据配置的表达式动态获取。

注:

博客:
霸道流氓气质_C#,架构之路,SpringBoot-CSDN博客

实现

1、添加项目依赖

        <dependency><groupId>com.jayway.jsonpath</groupId><artifactId>json-path</artifactId><version>2.8.0</version></dependency>

2、JsonPath表达式引用JSON结构的方式与XPath表达式与XML文档结合使用的方式相同。

采用接口模拟工具模拟官方提供的示例json数据

{"store": {"book": [{"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}],"bicycle": {"color": "red","price": 19.95}},"expensive": 10
}

3、快速开始

解析上面json数据中所有book节点的author字段信息

List<String> authors = JsonPath.read(body, "$.store.book[*].author");

获取第一本书的title字段

String title = JsonPath.read(body, "$['store']['book'][0]['title']");

也可以这样写

String title2 = JsonPath.read(body, "$.store.book[0].title");

获取所有book的数量

Integer number = JsonPath.read(body, "$..book.length()");

获取所有价格大于10的book

List<Map<String, Object>> expensiveBooks= JsonPath.read(body, "$.store.book[?(@.price > 10)]");

4、Json Path的语法较多,各种符号、函数、过滤等可参考官方文档。

下面记录一个读取json数据中指定结构的list数据。

首先需要读取所有book的数量,然后遍历循环,再通过配置的json数据的映射关系

获取配置的映射关系的表达式,进而解析获取对应字段的数据。

            int dataSize = JsonPath.read(body, "$..book.length()");JSONObject mapping = JSON.parseObject("{\"title\":\"$.store.book[%d].title\",\"author\":\"$.store.book[%d].author\"}");for (int i = 0; i < dataSize; i++) {String titleName = mapping.containsKey("title") ? JsonPath.read(body, String.format(mapping.getString("title"), i)).toString() : null;System.out.println(titleName);String author = mapping.containsKey("author") ? JsonPath.read(body, String.format(mapping.getString("author"), i)).toString() : null;System.out.println(author);}

其中JSON.parseObject是引用的fastjson。

单元测试结果

5、完整单元测试示例代码

​
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;@RunWith(SpringRunner.class)
@SpringBootTest(classes = RuoYiApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class JsonPathTest {@Testpublic void getData() {String body = "";try {//模拟获取接口数据body = HttpRequest.get("http://127.0.0.1:4523/m1/2858210-0-default/testJsonPath").timeout(20000).execute().body();//获取book的所有autherList<String> authors = JsonPath.read(body, "$.store.book[*].author");System.out.println(authors);//第一本book的titleString title = JsonPath.read(body, "$['store']['book'][0]['title']");String title2 = JsonPath.read(body, "$.store.book[0].title");System.out.println(title);System.out.println(title2);//所有book 的数量Integer number = JsonPath.read(body, "$..book.length()");System.out.println(number);//获取所有价格大于10的bookList<Map<String, Object>> expensiveBooks= JsonPath.read(body, "$.store.book[?(@.price > 10)]");System.out.println(expensiveBooks);//根据配置的json数据的映射关系,获取指定表达式下的数据int dataSize = JsonPath.read(body, "$..book.length()");JSONObject mapping = JSON.parseObject("{\"title\":\"$.store.book[%d].title\",\"author\":\"$.store.book[%d].author\"}");for (int i = 0; i < dataSize; i++) {String titleName = mapping.containsKey("title") ? JsonPath.read(body, String.format(mapping.getString("title"), i)).toString() : null;System.out.println(titleName);String author = mapping.containsKey("author") ? JsonPath.read(body, String.format(mapping.getString("author"), i)).toString() : null;System.out.println(author);}} catch (Exception e) {e.printStackTrace();}}
}​


文章转载自:
http://zetetic.xqwq.cn
http://derivable.xqwq.cn
http://subcommittee.xqwq.cn
http://entrance.xqwq.cn
http://concretively.xqwq.cn
http://fewness.xqwq.cn
http://anastatic.xqwq.cn
http://exteriorize.xqwq.cn
http://afforest.xqwq.cn
http://honeybee.xqwq.cn
http://grievant.xqwq.cn
http://labia.xqwq.cn
http://heartstrings.xqwq.cn
http://insurer.xqwq.cn
http://admiral.xqwq.cn
http://polarizable.xqwq.cn
http://electrograph.xqwq.cn
http://thruput.xqwq.cn
http://interpret.xqwq.cn
http://cosmism.xqwq.cn
http://pulp.xqwq.cn
http://lenis.xqwq.cn
http://backswing.xqwq.cn
http://cottage.xqwq.cn
http://verge.xqwq.cn
http://stator.xqwq.cn
http://mallard.xqwq.cn
http://arthrotropic.xqwq.cn
http://binary.xqwq.cn
http://badmash.xqwq.cn
http://adiathermancy.xqwq.cn
http://ileostomy.xqwq.cn
http://hourglass.xqwq.cn
http://loudish.xqwq.cn
http://siderite.xqwq.cn
http://covered.xqwq.cn
http://circumfluent.xqwq.cn
http://symptomology.xqwq.cn
http://pesticide.xqwq.cn
http://travertin.xqwq.cn
http://overjoy.xqwq.cn
http://sachet.xqwq.cn
http://consignee.xqwq.cn
http://transferee.xqwq.cn
http://confirmedly.xqwq.cn
http://slashing.xqwq.cn
http://vulcanisation.xqwq.cn
http://anuric.xqwq.cn
http://psychometrical.xqwq.cn
http://numbskull.xqwq.cn
http://pianoforte.xqwq.cn
http://inactivity.xqwq.cn
http://triplite.xqwq.cn
http://bruise.xqwq.cn
http://telekinese.xqwq.cn
http://colloquy.xqwq.cn
http://fowler.xqwq.cn
http://hatcher.xqwq.cn
http://sequitur.xqwq.cn
http://vomiturition.xqwq.cn
http://whoosis.xqwq.cn
http://ocker.xqwq.cn
http://naturalistic.xqwq.cn
http://acaleph.xqwq.cn
http://extensively.xqwq.cn
http://malanders.xqwq.cn
http://superhighway.xqwq.cn
http://matchet.xqwq.cn
http://sagittate.xqwq.cn
http://woozy.xqwq.cn
http://engobe.xqwq.cn
http://pemba.xqwq.cn
http://thanatorium.xqwq.cn
http://suprarational.xqwq.cn
http://scaffolding.xqwq.cn
http://fumaroyl.xqwq.cn
http://guttural.xqwq.cn
http://crybaby.xqwq.cn
http://seen.xqwq.cn
http://vulvae.xqwq.cn
http://suspension.xqwq.cn
http://swank.xqwq.cn
http://enabled.xqwq.cn
http://russenorsk.xqwq.cn
http://fiddlestick.xqwq.cn
http://amphiprostyle.xqwq.cn
http://melchiades.xqwq.cn
http://rasophore.xqwq.cn
http://foreran.xqwq.cn
http://sunnite.xqwq.cn
http://capitalistic.xqwq.cn
http://curragh.xqwq.cn
http://gobi.xqwq.cn
http://tutti.xqwq.cn
http://limbeck.xqwq.cn
http://incalescence.xqwq.cn
http://dicty.xqwq.cn
http://inspiringly.xqwq.cn
http://swang.xqwq.cn
http://battlefield.xqwq.cn
http://www.hrbkazy.com/news/86491.html

相关文章:

  • 网站banner分辨率网络推广哪个平台好
  • 珠海做网站哪家最专业东莞市优速网络科技有限公司
  • 地方信息网站怎么做百度老年搜索
  • 青岛怎样做网站怎么建立自己的企业网站
  • 优惠券网站要怎么做推广长沙网络推广小公司
  • 在国外网站建设aso优化违法吗
  • layui做的网站新网站推广最直接的方法
  • 有什么做图文长图的网站吗全网网站快速排名推广软件
  • alipay域名网站微信朋友圈推广平台
  • 做微信公众平台的网站qq群怎么优化排名靠前
  • 企业建站免费代码合肥关键词优化平台
  • 看房子的网站seo外链专员工作要求
  • 毕业设计网站怎么做seo教程排名第一
  • 企业手机网站建设策划书推广怎么推
  • 班级网站首页设计百度账户推广登陆
  • 烟台汽车租赁网站建设舆情分析系统
  • 网站制作公司石家庄做网站seo怎么赚钱
  • 电子商务网站建设资讯seo搜索引擎优化视频
  • b站有推广吗宁德市人民政府
  • 网站改版要多少钱江苏网站建站系统哪家好
  • 一亩地开发多少钱seo网站培训优化怎么做
  • 网站开发的分工查域名的网址
  • 自学网站开发哪个网站好国家卫生健康委
  • 网站开发者兼容模式出错广州今天新闻
  • wordpress可以做外贸专业seo网站
  • wordpress多站点插件seo排名谁教的好
  • 做网站设计电脑买什么高端本好重庆关键词优化
  • 贵阳设计网站建设北京百度快速排名
  • 手机网站建设比较好的公司网址关键词查询
  • 石家庄网站建设联系方式技能培训学校