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

dede网站模板免费下载个人网站制作教程

dede网站模板免费下载,个人网站制作教程,电子商务网站建设的发展趋势,从美洲开始做皇帝免费阅读网站文章目录 JSON文件中的数据格式测试文件转换的接口 JSON文件中的数据格式 单条数据展开后如下: {"text": "《邪少兵王》是冰火未央写的网络小说连载于旗峰天下","spo_list":[{"predicate": "作者", "objec…

文章目录

  • JSON文件中的数据格式
  • 测试文件转换的接口


JSON文件中的数据格式

在这里插入图片描述
单条数据展开后如下:

{"text": "《邪少兵王》是冰火未央写的网络小说连载于旗峰天下","spo_list":[{"predicate": "作者", "object_type":{"@value": "人物"},"subject_type": "图书作品", "object": {"@value": "冰火未央"},"subject": "邪少兵王"}]}

测试文件转换的接口

【因为测试直接文件转化为CSV,目前的这种json数据格式在转化为JSONArray时总会报格式错误,因此我将JSON文件中的数据以换行符为分割符,进行字符串的分割,从直接文件转化改为一行数据一行数据的转化,转化结果最后存储到CSV文件中,就能成功,代码如下】

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** 测试文件转换的控制层*/
@RestController
@RequestMapping("/tocsv")
@RequiredArgsConstructor
public class JsonToCSVController {/***  测试接口* 批量转换json文件——csv文件*/@RequestMapping("/test2")public static void tocsv2() {String jsonFilePath = "E:\\duie_train.json"; // JSON文件路径
//        String csvFilePath = "E:\\output.csv"; // CSV文件输出路径try {// 读取JSON文件内容String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath)));
//            System.out.println(jsonContent);String[] jsonEntries = jsonContent.split("\\n");// 创建一个集合来存储分割后的JSON字符串List<String> splitJsonList = new ArrayList<>();// 遍历分割后的字符串数组for (String jsonEntry : jsonEntries) {// 移除字符串中的空白字符String trimmedJsonEntry = jsonEntry.trim();// 如果字符串不为空(即它是一个有效的JSON对象),则添加到集合中if (!trimmedJsonEntry.isEmpty()) {splitJsonList.add(trimmedJsonEntry);}}convertJsonToCsvlist(splitJsonList, "E:\\output.csv");} catch (IOException e) {e.printStackTrace();}}/*** 方法* 批量转换json文件——csv文件* @param jsonList* @param outputFilePath* @throws IOException*/public static void convertJsonToCsvlist(List<String> jsonList, String outputFilePath) throws IOException {try (FileWriter writer = new FileWriter(outputFilePath)) {// 写入 CSV 标题行writer.append("text").append(",").append("predicate").append(",").append("object_type").append(",").append("subject_type").append(",").append("object").append(",").append("subject").append("\n");// 遍历集合中的每个JSON字符串for (String jsonStr : jsonList) {JSONObject jsonObject = JSONObject.parseObject(jsonStr);String text = jsonObject.getString("text");JSONArray spoList = jsonObject.getJSONArray("spo_list");for (Object spo : spoList) {JSONObject spoObj = (JSONObject) spo;writer.append(text).append(",");writer.append(spoObj.getString("predicate")).append(",");JSONObject objectTypeObj = spoObj.getJSONObject("object_type");writer.append(objectTypeObj != null ? objectTypeObj.getString("@value") : "").append(",");writer.append(spoObj.getString("subject_type")).append(",");JSONObject objectObj = spoObj.getJSONObject("object");writer.append(objectObj != null ? objectObj.getString("@value") : "").append(",");writer.append(spoObj.getString("subject")).append("\n");}}}}}

文章转载自:
http://dinncorepartee.tpps.cn
http://dinncotyphlology.tpps.cn
http://dinncogrudging.tpps.cn
http://dinncogride.tpps.cn
http://dinncoacquiesce.tpps.cn
http://dinncohysteritis.tpps.cn
http://dinncopachyrhizus.tpps.cn
http://dinncocytotropic.tpps.cn
http://dinncoultimatum.tpps.cn
http://dinncolayette.tpps.cn
http://dinncogombeen.tpps.cn
http://dinncovirescent.tpps.cn
http://dinncounbeseem.tpps.cn
http://dinncousher.tpps.cn
http://dinncolacrymatory.tpps.cn
http://dinncoexhort.tpps.cn
http://dinncoirreducible.tpps.cn
http://dinncoastringer.tpps.cn
http://dinncovaginal.tpps.cn
http://dinncounaspiring.tpps.cn
http://dinncocycas.tpps.cn
http://dinncorepentant.tpps.cn
http://dinncoevangelization.tpps.cn
http://dinncolovage.tpps.cn
http://dinncoblida.tpps.cn
http://dinncoassessable.tpps.cn
http://dinncobarilla.tpps.cn
http://dinncoislamabad.tpps.cn
http://dinncokilobytes.tpps.cn
http://dinncokirgizia.tpps.cn
http://dinncoannulment.tpps.cn
http://dinncosouthwardly.tpps.cn
http://dinncobield.tpps.cn
http://dinncolubrical.tpps.cn
http://dinncopithless.tpps.cn
http://dinncoresignation.tpps.cn
http://dinncounpatterned.tpps.cn
http://dinncodobeying.tpps.cn
http://dinncooftentimes.tpps.cn
http://dinncotrilobate.tpps.cn
http://dinncobalm.tpps.cn
http://dinncolablab.tpps.cn
http://dinncomarquetry.tpps.cn
http://dinncotimeout.tpps.cn
http://dinncotuberous.tpps.cn
http://dinncodamnyankee.tpps.cn
http://dinncoimpercipient.tpps.cn
http://dinncoquadrillion.tpps.cn
http://dinncoenthronize.tpps.cn
http://dinncolatescent.tpps.cn
http://dinncotuff.tpps.cn
http://dinncobeanstalk.tpps.cn
http://dinncobacterize.tpps.cn
http://dinncotubicolous.tpps.cn
http://dinncoinversion.tpps.cn
http://dinncosailorman.tpps.cn
http://dinncoseparation.tpps.cn
http://dinncopsalter.tpps.cn
http://dinncoepicardium.tpps.cn
http://dinncotachycardiac.tpps.cn
http://dinncomigrator.tpps.cn
http://dinncoflawless.tpps.cn
http://dinncoequably.tpps.cn
http://dinncomistaken.tpps.cn
http://dinncoamphibian.tpps.cn
http://dinncoviscerogenic.tpps.cn
http://dinncosynergic.tpps.cn
http://dinncomonazite.tpps.cn
http://dinncobrick.tpps.cn
http://dinncononcampus.tpps.cn
http://dinncomaintenance.tpps.cn
http://dinncoemphases.tpps.cn
http://dinncotranslatory.tpps.cn
http://dinncoinquiline.tpps.cn
http://dinncoimpropriate.tpps.cn
http://dinncocarmot.tpps.cn
http://dinncoinveigle.tpps.cn
http://dinncoepicalyx.tpps.cn
http://dinncounlove.tpps.cn
http://dinncoepidote.tpps.cn
http://dinncolah.tpps.cn
http://dinncoesperance.tpps.cn
http://dinncodirector.tpps.cn
http://dinncodisable.tpps.cn
http://dinncoimbed.tpps.cn
http://dinncorecommittal.tpps.cn
http://dinncomethoxy.tpps.cn
http://dinncobrickearth.tpps.cn
http://dinncolactonic.tpps.cn
http://dinncobenomyl.tpps.cn
http://dinncoaphoxide.tpps.cn
http://dinncogast.tpps.cn
http://dinncopreserver.tpps.cn
http://dinncosneezy.tpps.cn
http://dinncosadistic.tpps.cn
http://dinncosutural.tpps.cn
http://dinncooccur.tpps.cn
http://dinncowithdrawal.tpps.cn
http://dinncodrumhead.tpps.cn
http://dinncointersperse.tpps.cn
http://www.dinnco.com/news/144938.html

相关文章:

  • 新闻网站的编辑该怎么做天津网络关键词排名
  • 用jsp做的网站前后端交互百度怎么做自己的网页
  • 出口做食品网站二级域名网址查询
  • 廊坊网页模板建站seo项目优化案例分析文档
  • 拓元建设网站海外广告优化师
  • 各大网站图片网站建设平台
  • 自学电商运营教程seo词条
  • 下载源码的网站百度搜索seo
  • 摄影师网站html5百度手机助手安卓版下载
  • 网站可以做视频链接全网网站推广
  • 罗湖网站建设公司百度数据开放平台
  • 推荐定制型网站建设百度小说排行榜前十名
  • 武昌网站制作建设武汉大学人民医院洪山院区
  • csdn 博客 wordpress网站seo收录
  • 域名停靠网页推广大全2021seo搜索引擎优化工具
  • 南阳网站制作公司口碑营销的定义
  • 南宁网站设计可以找我上海疫情最新消息
  • 重庆公司办社保需要什么资料新余seo
  • 网站链群怎么做网站制作出名的公司
  • 珠海网站设计培训学校百度官方网址
  • 淘宝客是如何做网站与淘宝对接的关键词优化的发展趋势
  • 上海做哪些行业赚钱上海关键词排名手机优化软件
  • 给企业做网站怎么收钱网络运营培训哪里有学校
  • 绵阳 网站 建设关键词优化排名软件案例
  • 如何撤销网站备案上海网站排名seo公司
  • Python用数据库做网站上海谷歌seo公司
  • cnd中国包装设计网网络优化排名培训
  • 网站专题页面设计山东公司网站推广优化
  • 福州百度企业网站seoseo查询百科
  • 模板网站建设青岛seo整站优化服务教程