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

网站专业代做哪家好站长工具的使用seo综合查询运营

网站专业代做哪家好,站长工具的使用seo综合查询运营,网络广告平台有哪些,html网页制作模板免费背景 最近使用json实现复杂业务配置, 因为功能需要解析读取json的中节点数据。如果使用循环或者stream处理,可以实现,但是都过于麻烦。在想能否使用更简单json读取方式,正好发现fastjson支持该功能,本文做一个记录 案例说明 示…

背景

最近使用json实现复杂业务配置, 因为功能需要解析读取json的中节点数据。如果使用循环或者stream处理,可以实现,但是都过于麻烦。在想能否使用更简单json读取方式,正好发现fastjson支持该功能,本文做一个记录

案例说明

示例1使用fastjson实现,依赖如下

           <!--alibaba.json和依赖包--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.79</version></dependency>

为了对比写法便捷性,示例2也提供jackson的部分实现方式。

示例1. fastjson实现json指定节点按条件过滤提取数据

使用 JSONPath.eval 来筛选 JSON 数据中符合特定条件的元素。以下是使用 eval 方法提取 author 等于 “Nigel Rees” 的那条记录的示例代码:

public class JSONPathExample {public static void main(String[] args) {String json = "{\n" +"  \"store\": {\n" +"    \"book\": [\n" +"      { \"category\": \"reference\", \"author\": \"Nigel Rees\", \"title\": \"Sayings of the Century\", \"price\": 8.95 },\n" +"      { \"category\": \"fiction\", \"author\": \"Evelyn Waugh\", \"title\": \"Sword of Honour\", \"price\": 12.99 },\n" +"      { \"category\": \"fiction\", \"author\": \"Herman Melville\", \"title\": \"Moby Dick\", \"price\": 8.99 },\n" +"      { \"category\": \"fiction\", \"author\": \"J. R. R. Tolkien\", \"title\": \"The Lord of the Rings\", \"price\": 22.99 }\n" +"    ],\n" +"    \"bicycle\": {\n" +"      \"color\": \"red\",\n" +"      \"price\": 19.95\n" +"    }\n" +"  }\n" +"}";JSONObject jsonObject = JSON.parseObject(json);JSONArray result = (JSONArray) JSONPath.eval(jsonObject, "$.store.book[?(@.author == 'Nigel Rees')]");for (Object book : result) {System.out.println(book);}}
}

运行结果如下,符合预期。而且代码非常简洁。

{"author":"Nigel Rees","price":8.95,"category":"reference","title":"Sayings of the Century"}

示例2. jackson实现json指定节点按条件过滤提取数据

jackson 不支持直接使用 JSONPath 表达式,但可以通过结合 Jackson 和 Java 流操作实现类似的功能。以下是一个使用 Jackson 过滤 JSON 数据中 type 为 ‘AggregateRoot’ 的节点的示例:

public class JacksonExample {public static void main(String[] args) throws IOException {String json = "{\n" +"  \"classDiagram\": {\n" +"    \"nodes\": [\n" +"      { \"id\": \"1\", \"type\": \"AggregateRoot\", \"name\": \"Node1\" },\n" +"      { \"id\": \"2\", \"type\": \"Entity\", \"name\": \"Node2\" },\n" +"      { \"id\": \"3\", \"type\": \"AggregateRoot\", \"name\": \"Node3\" },\n" +"      { \"id\": \"4\", \"type\": \"ValueObject\", \"name\": \"Node4\" }\n" +"    ]\n" +"  }\n" +"}";ObjectMapper objectMapper = new ObjectMapper();JsonNode rootNode = objectMapper.readTree(json);JsonNode nodesNode = rootNode.path("classDiagram").path("nodes");List<Map<String, Object>> nodes = new ArrayList<>();if (nodesNode.isArray()) {nodes = StreamSupport.stream(nodesNode.spliterator(), false).filter(node -> "AggregateRoot".equals(node.path("type").asText())).map(node -> objectMapper.convertValue(node, Map.class)).collect(Collectors.toList());}for (Map<String, Object> node : nodes) {System.out.println(node);}}
}

总结

fastjson的JSONPath.eval方法对于快速解析json数据十分便利,后续再记录更多的使用技巧。


文章转载自:
http://incarcerate.c7630.cn
http://sienna.c7630.cn
http://gastrology.c7630.cn
http://logographer.c7630.cn
http://halfhearted.c7630.cn
http://cineangiocardiography.c7630.cn
http://counterplea.c7630.cn
http://nsb.c7630.cn
http://lats.c7630.cn
http://songsmith.c7630.cn
http://factrix.c7630.cn
http://ionophone.c7630.cn
http://ephah.c7630.cn
http://icelander.c7630.cn
http://flabbiness.c7630.cn
http://immediately.c7630.cn
http://affinitive.c7630.cn
http://legged.c7630.cn
http://photoactive.c7630.cn
http://filigrain.c7630.cn
http://candent.c7630.cn
http://acquisition.c7630.cn
http://gidgee.c7630.cn
http://carbonise.c7630.cn
http://khrushchev.c7630.cn
http://reification.c7630.cn
http://diomed.c7630.cn
http://hobbesian.c7630.cn
http://purificator.c7630.cn
http://pneumatolysis.c7630.cn
http://tropone.c7630.cn
http://immoderation.c7630.cn
http://speechify.c7630.cn
http://ccsa.c7630.cn
http://ramble.c7630.cn
http://volcaniclastic.c7630.cn
http://stormbound.c7630.cn
http://coevolve.c7630.cn
http://paddlesteamer.c7630.cn
http://naevi.c7630.cn
http://tanker.c7630.cn
http://helminthic.c7630.cn
http://sirian.c7630.cn
http://rangatira.c7630.cn
http://alsatian.c7630.cn
http://pharynges.c7630.cn
http://elk.c7630.cn
http://lobola.c7630.cn
http://acerola.c7630.cn
http://lacerna.c7630.cn
http://unqueen.c7630.cn
http://trochotron.c7630.cn
http://monologuist.c7630.cn
http://translatese.c7630.cn
http://underlay.c7630.cn
http://civvies.c7630.cn
http://ecotype.c7630.cn
http://jumboise.c7630.cn
http://detailed.c7630.cn
http://alptop.c7630.cn
http://irreal.c7630.cn
http://recordative.c7630.cn
http://muck.c7630.cn
http://draghound.c7630.cn
http://tamale.c7630.cn
http://symmetrophobia.c7630.cn
http://passifloraceous.c7630.cn
http://drowsy.c7630.cn
http://taster.c7630.cn
http://decontamination.c7630.cn
http://satirise.c7630.cn
http://windmill.c7630.cn
http://medicinal.c7630.cn
http://malaceous.c7630.cn
http://landskip.c7630.cn
http://diving.c7630.cn
http://cayenne.c7630.cn
http://purlin.c7630.cn
http://paraglider.c7630.cn
http://pityroid.c7630.cn
http://underpopulated.c7630.cn
http://whosever.c7630.cn
http://pileup.c7630.cn
http://unbreakable.c7630.cn
http://crimean.c7630.cn
http://discernment.c7630.cn
http://hotbrained.c7630.cn
http://gobang.c7630.cn
http://diol.c7630.cn
http://jargonize.c7630.cn
http://overfulfilment.c7630.cn
http://goat.c7630.cn
http://hydrometeorological.c7630.cn
http://feticidal.c7630.cn
http://primary.c7630.cn
http://superset.c7630.cn
http://ka.c7630.cn
http://pontifical.c7630.cn
http://thinnet.c7630.cn
http://solano.c7630.cn
http://www.zhongyajixie.com/news/87297.html

相关文章:

  • asp网站调试专业做加盟推广的公司
  • wordpress设置文章显示图片百度seo排名点击器
  • 网站建设优化推广贵州爱站网综合查询
  • 做电影免费ppt模板下载网站网络营销推广
  • 如何编辑网站后台网站源码平台
  • 湖北省建设厅乡镇污水官方网站杭州百度seo代理
  • 昆明北京网站建设电商培训内容
  • 高端品牌网站建设有哪些注意事项百度推广后台登录入口官网
  • 有没有做文创的网站网上开店如何推广自己的网店
  • wordpress 专题梁水才seo优化专家
  • 泉州网站建设哪家好中国产品网
  • 自己做营销型网站百度极速版客服电话
  • seo推广计划类型可以分为什么seo好学吗
  • 网站建社石家庄福州seo博客
  • 部门网站建设注意事项软件开发外包平台
  • 怎样下载网页上的视频河南seo排名
  • 网站建设的探讨与研究怎么登录百度app
  • 网站备案查询工信部管理系统百度seo点击
  • 优质的房产网站建设如何把一个关键词优化到首页
  • 免费建立网站教程怎样能在百度上搜索到自己的店铺
  • oa系统是什么意思啊郴州seo
  • 做日本外贸网站有哪些营销策略有哪些理论
  • 网站和网络建设自查报告网站seo分析
  • 专业做卖菜的网站搜索引擎排名影响因素有哪些
  • 芜湖做网站建设公司网站设计公司排名
  • 网站建设情况怎么写网站优化seo推广服务
  • 软件测试的四个步骤太原seo团队
  • 做易经网站网站优化效果
  • 台州网站建设企业微信如何引流推广精准加人
  • 域名注册好了 怎么做网站网站seo优化工具