首页 > 其他分享 >解析json数据导出某个字段的值到excel(记录)

解析json数据导出某个字段的值到excel(记录)

时间:2023-08-07 12:37:40浏览次数:28  
标签:String mobile excel System source json println 字段 out


记录一下导出代码

public static void main(String[] args) {
		// 将你的json数据放在txt文档里并复制路径到下面
        String filePath = "E:/home/2023年需求/人才/20230801出表/job_mobile_json.txt";  // 替换成你的文件路径

        try {
            String content = readFileAsString(filePath);
//            System.out.println(content);
            int emptyTotal = 0;
            int notNullTotal = 0;
            for (Object object : JSON.parseArray(content)) {
                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(object));
                JSONObject source = jsonObject.getJSONObject("_source");
                if (Objects.nonNull(source) && !source.toString().equals("{}")) {
                    JSONObject jobUser = source.getJSONObject("jobUser");
                    String mobile = jobUser.getString("mobile");
                    if(StringUtils.isNotEmpty(mobile)){
                        System.out.println(mobile);
                        notNullTotal ++;
                    }else{
                        emptyTotal++;
                    }
                }else{
                    emptyTotal++;
                }

            }
            System.out.println("不为空:"+notNullTotal);
            System.out.println("为空:"+emptyTotal);


        } catch (IOException e) {
            System.err.println("Failed to read file: " + e.getMessage());
        }
    }

    public static String readFileAsString(String filePath) throws IOException {
        Path path = Paths.get(filePath);
        byte[] bytes = Files.readAllBytes(path);
        return new String(bytes);
    }


标签:String,mobile,excel,System,source,json,println,字段,out
From: https://blog.51cto.com/u_15473875/6992413

相关文章

  • excel 合并单元格内容数据写入
    youcanusethiscodetoopen(test.xlsx)fileandmodifyA1cellandthensaveitwithanewnameimportopenpyxlxfile=openpyxl.load_workbook('test.xlsx')sheet=xfile.get_sheet_by_name('Sheet1')sheet['A1']='hel......
  • Bazel 如何生成 clangd/clang-tidy 所需的 compile_commands.json
    VSCode中如何使用clang-tidy安装clangd插件禁用ms-cpp插件(VSCode会自动提示有冲突)生成clangd所需的compile_commands.json文件如何生成compile_commands.json文件修改WORKSPACE,添加以下内容load("@bazel_tools//tools/build_defs/repo:http.bzl","http_a......
  • Javaexcel文件读取,插入到数据库中
    你可以使用Java的ApachePOI库来读取Excel文件,并使用JDBC连接数据库将数据插入到数据库中。下面是一个示例代码:importjava.io.FileInputStream;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importorg.apache.poi.ss.usermo......
  • json2yolo
    json2yolo脚本yolo所对应的格式是.txt,其中包含框的类别索引,中心点坐标,boundingboxs的宽,高。importjsonimportos#由x1,y1,x2,y2---->Cx,Cy,W,H相对位置(取值范围0-1)name2id={'person':0,'mask':1}#写好自己的类别和标签defconvert(img_size,box):......
  • swoole使用JSONP方式解决跨域
    文档说明:只记录关键地方;文档创建时间:2023-08-06;目标:使用JSONP方式解决跨域备注:常用到的功能记录一下,方便复制<?phpuseSwoole\Http\Request;useSwoole\Http\Response;useSwoole\Coroutine\Http\Server;usefunctionSwoole\Coroutine\run;run(function(){......
  • 记录小知识 数据库设置自动填充更新创建字段时间
    1,在数据库中设置该字段类型为timestamp  2,设置默认值为 CURRENT_TIMESTAMP3,更新字段需要点击勾选根据当前时间戳更新 而创建时间是不需要勾选的因为创建只需要一次 ......
  • 如何快速对比两张Excel报表
    背景最近由于工作原因,要切换系统,新老系统都会产生excel报表,上线前需要验证新老系统产生的报表数据的一致性,作为测试的一部分。理论上,是要求新老系统新生成的报表要一模一样,要是不一致的地方,也需要标注出合理的解释。本文地址:https://www.cnblogs.com/hchengmx/p/17609130.html......
  • ORM 字段和参数
    一、ORM字段1、常用字段AutoFieldint自增列,必须填入参数primary_key=True。当model中如果没有自增列,则自动会创建一个列名为id的列。  IntegerField一个整数类型,范围在-2147483648to2147483647。 CharField字符类型,必须提供max_length参数,max_length表示字符长度。......
  • post时间盲注查询表字段数所新增的类属性
    self.information_schema_GLOBAL_STATUS=[2]self.information_schema_GLOBAL_VARIABLES=[2]self.information_schema_REFERENTIAL_CONSTRAINTS=[11]self.information_schema_PLUGINS=[11]self.information_schema_COLLATIONS=[6]self.information_schema_TABLE......
  • post时间盲注注入脚本之查询表字段数--草稿
    importrequestsimportsysimporttimeimportpdbimportthreadingfromconcurrent.futuresimportThreadPoolExecutorclassInjection():def__init__(self):self.url=""#self.scheNum=0self.scheNum=7#sel......