IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> java递归替换 -> 正文阅读

[大数据]java递归替换

递归替换,老蔡牛逼

package com.plus.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sun.media.sound.SoftTuning;
import sun.reflect.generics.tree.VoidDescriptor;

public class NodeTreeTest {

    public static void main(String[] args) {
        String  node="{\n" +
                "    \"code\": \"0000\",\n" +
                "    \"msg\": \"数据响应正确!\",\n" +
                "    \"data\": [\n" +
                "        {\n" +
                "            \"inv\": [\n" +
                "                {\n" +
                "                    \"FINALENTNAME\": \"深圳市人民政府国有资产监督管理委员会\",\n" +
                "                    \"POSITION\": \"\",\n" +
                "                    \"FINALACCONAM\": \"-\",\n" +
                "                    \"CAPITALCHAIN\": \"深圳市人民政府国有资产监督管理委员会 -> 深圳市地铁集团有限公司 -> 万科企业股份有限公司\",\n" +
                "                    \"FINALSUBCONAM\": \"-\",\n" +
                "                    \"FINALRATIO\": \"27.61%\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"FINALENTNAME\": \"郁亮\",\n" +
                "                    \"POSITION\": \"法人\",\n" +
                "                    \"FINALACCONAM\": \"-\",\n" +
                "                    \"CAPITALCHAIN\": \"郁亮 -> 万科企业股份有限公司\",\n" +
                "                    \"FINALSUBCONAM\": \"-\",\n" +
                "                    \"FINALRATIO\": \"\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"node\": {\n" +
                "                \"name\": \"万科企业股份有限公司\",\n" +
                "                \"subnode\": [\n" +
                "                    {\n" +
                "                        \"conprop\": \"1.26\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"招商财富-招商银行-德赢1号专项资产管理计划\",\n" +
                "                        \"real_conprop\": \"1.26\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"1.14\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"中国证券金融股份有限公司\",\n" +
                "                        \"real_conprop\": \"1.14\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"3.77\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"深圳盈嘉众实业合伙企业(有限合伙)\",\n" +
                "                        \"real_conprop\": \"3.77\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [\n" +
                "                            {\n" +
                "                                \"conprop\": \"100.0\",\n" +
                "                                \"address\": \"\",\n" +
                "                                \"level\": 2,\n" +
                "                                \"certype\": \"\",\n" +
                "                                \"idcard\": \"\",\n" +
                "                                \"name\": \"深圳盈安财务顾问企业(有限合伙)\",\n" +
                "                                \"real_conprop\": \"3.77\",\n" +
                "                                \"position\": \"\",\n" +
                "                                \"subconam\": \"\",\n" +
                "                                \"subnode\": [\n" +
                "                                    {\n" +
                "                                        \"conprop\": \"99.72\",\n" +
                "                                        \"address\": \"\",\n" +
                "                                        \"level\": 3,\n" +
                "                                        \"certype\": \"\",\n" +
                "                                        \"idcard\": \"\",\n" +
                "                                        \"name\": \"华能贵诚信托有限公司\",\n" +
                "                                        \"real_conprop\": \"3.75944\",\n" +
                "                                        \"position\": \"\",\n" +
                "                                        \"subconam\": \"\",\n" +
                "                                        \"subnode\": [\n" +
                "                                            {\n" +
                "                                                \"conprop\": \"67.92\",\n" +
                "                                                \"address\": \"\",\n" +
                "                                                \"level\": 4,\n" +
                "                                                \"certype\": \"\",\n" +
                "                                                \"idcard\": \"\",\n" +
                "                                                \"name\": \"华能资本服务有限公司\",\n" +
                "                                                \"real_conprop\": \"2.55341\",\n" +
                "                                                \"position\": \"\",\n" +
                "                                                \"subconam\": \"\",\n" +
                "                                                \"subnode\": [\n" +
                "                                                    {\n" +
                "                                                        \"conprop\": \"61.22\",\n" +
                "                                                        \"address\": \"\",\n" +
                "                                                        \"level\": 5,\n" +
                "                                                        \"certype\": \"\",\n" +
                "                                                        \"idcard\": \"\",\n" +
                "                                                        \"name\": \"中国华能集团有限公司\",\n" +
                "                                                        \"real_conprop\": \"1.5632\",\n" +
                "                                                        \"position\": \"\",\n" +
                "                                                        \"subconam\": \"\",\n" +
                "                                                        \"subnode\": [\n" +
                "                                                            {\n" +
                "                                                                \"conprop\": \"100.0\",\n" +
                "                                                                \"address\": \"\",\n" +
                "                                                                \"level\": 6,\n" +
                "                                                                \"certype\": \"\",\n" +
                "                                                                \"idcard\": \"\",\n" +
                "                                                                \"name\": \"国务院国有资产监督管理委员会\",\n" +
                "                                                                \"real_conprop\": \"1.5632\",\n" +
                "                                                                \"position\": \"\",\n" +
                "                                                                \"subconam\": \"\",\n" +
                "                                                                \"subnode\": [],\n" +
                "                                                                \"tags\": \"1\"\n" +
                "                                                            }\n" +
                "                                                        ],\n" +
                "                                                        \"tags\": \"1\"\n" +
                "                                                    }\n" +
                "                                                ],\n" +
                "                                                \"tags\": \"1\"\n" +
                "                                            },\n" +
                "                                            {\n" +
                "                                                \"conprop\": \"31.48\",\n" +
                "                                                \"address\": \"\",\n" +
                "                                                \"level\": 4,\n" +
                "                                                \"certype\": \"\",\n" +
                "                                                \"idcard\": \"\",\n" +
                "                                                \"name\": \"贵州乌江能源投资有限公司\",\n" +
                "                                                \"real_conprop\": \"1.18347\",\n" +
                "                                                \"position\": \"\",\n" +
                "                                                \"subconam\": \"\",\n" +
                "                                                \"subnode\": [\n" +
                "                                                    {\n" +
                "                                                        \"conprop\": \"100.0\",\n" +
                "                                                        \"address\": \"\",\n" +
                "                                                        \"level\": 5,\n" +
                "                                                        \"certype\": \"\",\n" +
                "                                                        \"idcard\": \"\",\n" +
                "                                                        \"name\": \"贵州乌江能源集团有限责任公司\",\n" +
                "                                                        \"real_conprop\": \"1.18347\",\n" +
                "                                                        \"position\": \"\",\n" +
                "                                                        \"subconam\": \"\",\n" +
                "                                                        \"subnode\": [],\n" +
                "                                                        \"tags\": \"1\"\n" +
                "                                                    }\n" +
                "                                                ],\n" +
                "                                                \"tags\": \"1\"\n" +
                "                                            }\n" +
                "                                        ],\n" +
                "                                        \"tags\": \"1\"\n" +
                "                                    }\n" +
                "                                ],\n" +
                "                                \"tags\": \"1\"\n" +
                "                            }\n" +
                "                        ],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"1.63\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"中央汇金资产管理有限责任公司\",\n" +
                "                        \"real_conprop\": \"1.63\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [\n" +
                "                            {\n" +
                "                                \"conprop\": \"100.0\",\n" +
                "                                \"address\": \"\",\n" +
                "                                \"level\": 2,\n" +
                "                                \"certype\": \"\",\n" +
                "                                \"idcard\": \"\",\n" +
                "                                \"name\": \"中央汇金投资有限责任公司\",\n" +
                "                                \"real_conprop\": \"1.63\",\n" +
                "                                \"position\": \"\",\n" +
                "                                \"subconam\": \"\",\n" +
                "                                \"subnode\": [\n" +
                "                                    {\n" +
                "                                        \"conprop\": \"100.0\",\n" +
                "                                        \"address\": \"\",\n" +
                "                                        \"level\": 3,\n" +
                "                                        \"certype\": \"\",\n" +
                "                                        \"idcard\": \"\",\n" +
                "                                        \"name\": \"中国投资有限责任公司\",\n" +
                "                                        \"real_conprop\": \"1.63\",\n" +
                "                                        \"position\": \"\",\n" +
                "                                        \"subconam\": \"\",\n" +
                "                                        \"subnode\": [\n" +
                "                                            {\n" +
                "                                                \"conprop\": \"100.0\",\n" +
                "                                                \"address\": \"\",\n" +
                "                                                \"level\": 4,\n" +
                "                                                \"certype\": \"\",\n" +
                "                                                \"idcard\": \"\",\n" +
                "                                                \"name\": \"国务院\",\n" +
                "                                                \"real_conprop\": \"1.63\",\n" +
                "                                                \"position\": \"\",\n" +
                "                                                \"subconam\": \"\",\n" +
                "                                                \"subnode\": [],\n" +
                "                                                \"tags\": \"4\"\n" +
                "                                            }\n" +
                "                                        ],\n" +
                "                                        \"tags\": \"1\"\n" +
                "                                    }\n" +
                "                                ],\n" +
                "                                \"tags\": \"1\"\n" +
                "                            }\n" +
                "                        ],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"16.35\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"HKSCC NOMINEES LIMITED\",\n" +
                "                        \"real_conprop\": \"16.35\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"27.61\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"深圳市地铁集团有限公司\",\n" +
                "                        \"real_conprop\": \"27.61\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [\n" +
                "                            {\n" +
                "                                \"conprop\": \"100.0\",\n" +
                "                                \"address\": \"\",\n" +
                "                                \"level\": 2,\n" +
                "                                \"certype\": \"\",\n" +
                "                                \"idcard\": \"\",\n" +
                "                                \"name\": \"深圳市人民政府国有资产监督管理委员会\",\n" +
                "                                \"real_conprop\": \"27.61\",\n" +
                "                                \"position\": \"\",\n" +
                "                                \"subconam\": \"\",\n" +
                "                                \"subnode\": [],\n" +
                "                                \"tags\": \"1\"\n" +
                "                            }\n" +
                "                        ],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"1.05\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"深圳盈安财务顾问企业(有限合伙)\",\n" +
                "                        \"real_conprop\": \"1.05\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [\n" +
                "                            {\n" +
                "                                \"conprop\": \"99.72\",\n" +
                "                                \"address\": \"\",\n" +
                "                                \"level\": 2,\n" +
                "                                \"certype\": \"\",\n" +
                "                                \"idcard\": \"\",\n" +
                "                                \"name\": \"华能贵诚信托有限公司\",\n" +
                "                                \"real_conprop\": \"1.04706\",\n" +
                "                                \"position\": \"\",\n" +
                "                                \"subconam\": \"\",\n" +
                "                                \"subnode\": [\n" +
                "                                    {\n" +
                "                                        \"conprop\": \"67.92\",\n" +
                "                                        \"address\": \"\",\n" +
                "                                        \"level\": 3,\n" +
                "                                        \"certype\": \"\",\n" +
                "                                        \"idcard\": \"\",\n" +
                "                                        \"name\": \"华能资本服务有限公司\",\n" +
                "                                        \"real_conprop\": \"0.71116\",\n" +
                "                                        \"position\": \"\",\n" +
                "                                        \"subconam\": \"\",\n" +
                "                                        \"subnode\": [\n" +
                "                                            {\n" +
                "                                                \"conprop\": \"61.22\",\n" +
                "                                                \"address\": \"\",\n" +
                "                                                \"level\": 4,\n" +
                "                                                \"certype\": \"\",\n" +
                "                                                \"idcard\": \"\",\n" +
                "                                                \"name\": \"中国华能集团有限公司\",\n" +
                "                                                \"real_conprop\": \"0.43537\",\n" +
                "                                                \"position\": \"\",\n" +
                "                                                \"subconam\": \"\",\n" +
                "                                                \"subnode\": [\n" +
                "                                                    {\n" +
                "                                                        \"conprop\": \"100.0\",\n" +
                "                                                        \"address\": \"\",\n" +
                "                                                        \"level\": 5,\n" +
                "                                                        \"certype\": \"\",\n" +
                "                                                        \"idcard\": \"\",\n" +
                "                                                        \"name\": \"国务院国有资产监督管理委员会\",\n" +
                "                                                        \"real_conprop\": \"0.43537\",\n" +
                "                                                        \"position\": \"\",\n" +
                "                                                        \"subconam\": \"\",\n" +
                "                                                        \"subnode\": [],\n" +
                "                                                        \"tags\": \"1\"\n" +
                "                                                    }\n" +
                "                                                ],\n" +
                "                                                \"tags\": \"1\"\n" +
                "                                            }\n" +
                "                                        ],\n" +
                "                                        \"tags\": \"1\"\n" +
                "                                    },\n" +
                "                                    {\n" +
                "                                        \"conprop\": \"31.48\",\n" +
                "                                        \"address\": \"\",\n" +
                "                                        \"level\": 3,\n" +
                "                                        \"certype\": \"\",\n" +
                "                                        \"idcard\": \"\",\n" +
                "                                        \"name\": \"贵州乌江能源投资有限公司\",\n" +
                "                                        \"real_conprop\": \"0.32961\",\n" +
                "                                        \"position\": \"\",\n" +
                "                                        \"subconam\": \"\",\n" +
                "                                        \"subnode\": [\n" +
                "                                            {\n" +
                "                                                \"conprop\": \"100.0\",\n" +
                "                                                \"address\": \"\",\n" +
                "                                                \"level\": 4,\n" +
                "                                                \"certype\": \"\",\n" +
                "                                                \"idcard\": \"\",\n" +
                "                                                \"name\": \"贵州乌江能源集团有限责任公司\",\n" +
                "                                                \"real_conprop\": \"0.32961\",\n" +
                "                                                \"position\": \"\",\n" +
                "                                                \"subconam\": \"\",\n" +
                "                                                \"subnode\": [],\n" +
                "                                                \"tags\": \"1\"\n" +
                "                                            }\n" +
                "                                        ],\n" +
                "                                        \"tags\": \"1\"\n" +
                "                                    }\n" +
                "                                ],\n" +
                "                                \"tags\": \"1\"\n" +
                "                            }\n" +
                "                        ],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"conprop\": \"5.27\",\n" +
                "                        \"address\": \"\",\n" +
                "                        \"level\": 1,\n" +
                "                        \"certype\": \"\",\n" +
                "                        \"idcard\": \"\",\n" +
                "                        \"name\": \"香港中央结算有限公司\",\n" +
                "                        \"real_conprop\": \"5.27\",\n" +
                "                        \"position\": \"\",\n" +
                "                        \"subconam\": \"\",\n" +
                "                        \"subnode\": [],\n" +
                "                        \"tags\": \"1\"\n" +
                "                    }\n" +
                "                ],\n" +
                "                \"tags\": \"1\"\n" +
                "            }\n" +
                "        }\n" +
                "    ]\n" +
                "}";



//        JSONObject node1 = new JSONObject();
//        node1.put("subnode", new JSONArray());
//        JSONObject js = new JSONObject();
//        js.put("name", "guizhouyinghang");
//        js.put("subnode", new JSONArray());
//        node1.getJSONArray("subnode").add(js);
//
//        JSONObject js2 = new JSONObject();
//        js2.put("name", "zhongyi");
//        js2.put("subnode", new JSONArray());
//        js.getJSONArray("subnode").add(js2);
//
//        JSONObject result = new JSONObject();
//        result.put("children", new JSONArray());

        JSONObject jsonObject = JSONObject.parseObject(node);
        JSONArray data = jsonObject.getJSONArray("data");
        JSONObject jsonObject1 = data.getJSONObject(0);
        JSONObject node1 = jsonObject1.getJSONObject("node");

        JSONObject result = new JSONObject();
        result.put("children", new JSONArray());
        test(result.getJSONArray("children"), node1.getJSONArray("subnode"));
        System.out.println(result.toJSONString());

}

    public static void test(JSONArray result, JSONArray jsonArr1) {
        if (jsonArr1.isEmpty()) {
            return;
        }

        for (int i = 0; i < jsonArr1.size(); i ++) {
            JSONObject jb1 = (JSONObject) jsonArr1.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("nodeName", jb1.get("name"));
            jsonObject.put("isEnt", jb1.get("tags"));
            jsonObject.put("nodeType", jb1.get("conprop"));
            jsonObject.put("children", new JSONArray());
            result.add(jsonObject);
            test((JSONArray) jsonObject.get("children"), (JSONArray) jb1.get("subnode"));
        }
    }
}

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-03-10 22:36:15  更:2022-03-10 22:40:21 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 9:53:47-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码