Gson 解析示例

{
    "bbu": {
        "rsTable": "wr_device_bbu",
        "rsPk": "bbu_id",
        "rsCuid": ["c3b11379-ffcd-0821-8f55-779b184b4e87"]
    },
    "rru": {
        "rsTable": "wr_device_rru",
        "rsPk": "rru_id",
        "rsCuid": ["864b492f-49a0-fc39-235d-3618d443b289", "ddd3437e-f42b-5f3f-e7ba-31b1592ff836", "bd323141-d2a5-866c-e4c9-ab6be8d696b5", "673d9664-70c6-6afb-9fae-b7fac7848c61", "74d1014e-52c0-bc76-141f-bc9535e5ca32", "d7230679-6cb0-ddc5-7ed5-53e5f46733e2", "cfca2be2-1b90-2b41-555a-f431eb50c6f7", "e5033d3d-ecb5-6577-1719-4de74c01929f", "1564684f-6d83-5c8f-7c9a-5750b7d49565", "8392eebd-928a-8092-bdf9-f72e7560c218", "93326c2c-f52c-d3f6-dd65-c1564034bab3", "67f0eece-6f48-9d6c-700d-af1f591b493c", "4c48bd08-fb34-c2ef-222c-850dea1996f8", "b98e7b69-49c0-5d50-ee7a-8a65402f68df", "10b7c76f-c8fd-0646-b76e-fe27f4b6642f", "5951229d-e933-8f7f-8a12-bf76cfa80629", "60cc6ef0-0a96-f9ff-b548-fbd9fa3e0a94"]
    },
    "wids": {
        "rsTable": "wr_device_wids",
        "rsPk": "wids_id",
        "rsCuid": ["e7a878bd-e4fa-6b71-180d-4a696d652c0a", "e8871ef5-673d-a216-ded3-14432311cdee", "4400f0c0-8545-950b-225c-189f3530a1a5", "c1c1f496-ac38-c20a-6ad7-0180c70fad41"]
    },
    "enodeb": {
        "rsTable": "wr_logic_enodeb",
        "rsPk": "enodeb_id",
        "rsCuid": ["e8fb167d-c5ca-947a-f62c-bd25eac8acf5"]
    },
    "eutrancell": {
        "rsTable": "wr_logic_eutrancell",
        "rsPk": "eutrancell_id",
        "rsCuid": ["6bbdd275-b8bd-e339-82f0-f0433b7c8ec8", "74f22088-00b6-563d-e656-9cc18ee9eb52", "e9634f20-0b12-ac72-f14c-dcf4ca8da4e2", "5bd1c352-9535-6a72-2f5b-df97956bcf26"]
    },
    "rru_cell": {
        "rsTable": "wr_map_rru_cell",
        "rsPk": "rru_cell_id",
        "rsCuid": ["3d972c91-727b-ba1e-4588-167c7e58bb16", "64b84ccb-c268-1c0c-5f09-ea18d345bd1c", "54c8c417-28d3-91ab-c1df-cf717455c9dd", "14004ac9-cdb2-60f0-d118-c4d8e97dae83", "17cf469a-0228-72d3-df4a-1911bd101aa1", "c55b7cae-9051-da6a-2e8e-ab31203f51be", "5849cacf-7e72-3270-393b-4b1e9af816ad", "e72a7957-7ca9-a127-74e5-f601fd6461e2", "c615d5df-7b48-2847-92ec-50e732eb41e8", "bb7c63de-45ba-8592-e519-fad26764671d", "4bb217e7-e918-a761-158c-f9803152eff4", "72bab9fc-a843-b281-da00-6fbdb1abb47d", "b8ddab76-7baf-e651-5029-1259dac851ab", "5b10aa78-2c3d-527a-991a-eef05d73e63d", "fbbfe9f0-29be-4ca1-bdd9-698e350c7293", "a718cffd-7031-ea0c-2d51-943b341004eb", "f8c7304a-5c0b-184b-e330-32c738cb9369"]
    },
    "wids_cell": {
        "rsTable": "wr_map_wids_cell",
        "rsPk": "wids_cell_id",
        "rsCuid": ["a69aacf4-2fe6-3bda-2b2d-f3d95341804f", "7cf7d96b-71b4-c7a1-2601-4c53401c57c8", "c73566e2-528b-4a51-3bac-205fd4824f97", "118ff72d-8e67-e533-fd91-31ea078e72da"]
    }
}

对应解析程序

package com.nokia.wfm.biz.business.test;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

//import net.sf.json.JSONObject;

/**
 * 测试接口
 *
 * @author liangzhaolin
 * @date 2019/10/18 22:17
 */
@Slf4j
@RestController
@RequestMapping("test")
public class Test2Controller {

    // 输出去重后的网元CUID
    public static void main(String[] args) throws IOException {
        File file = new File("E:\\Allen\\Documents\\临时文件\\temp44.json");
        List<String> recordList = FileUtils.readLines(file,"utf-8");

        Set<String> totalSet = new HashSet<>();

        Gson gson = new Gson();

        Type type = new TypeToken<Map<String, NetVO>>() {}.getType();

        for (String record: recordList) {
            Map<String, NetVO> recordMap = gson.fromJson(record, type);

            for (Map.Entry<String, NetVO> entry: recordMap.entrySet()) {
                String netType = entry.getKey();
                NetVO oneNetVO = (NetVO) entry.getValue();

                addSet(totalSet, oneNetVO, netType);
            }
        }

        System.out.println(totalSet);
    }

    private static void addSet(Set<String> totalSet, NetVO netVO, String netType) {
        if (netVO != null) {
            List<String> cuidList = netVO.getRsCuid();
            for (String rsCuid : cuidList) {
                totalSet.add(netType + "," + rsCuid);
            }
        }
    }

    private static void addList(List<String> totalList, NetVO netVO) {
        if (netVO != null) {
            List<String> cuidList = netVO.getRsCuid();
            for (String rsCuid : cuidList) {
                totalList.add(rsCuid);
            }
        }
    }

}

输出结果:

[tower,34d7f688-a452-e308-d5d2-244c4bf21fd1, wids_cell,3015cb53-dbfc-fead-a322-0a3865fe5a97, rru_cell,c2306139-10f9-f9ed-ebad-878b1c43c0d3, eutrancell,0c6c9a76-9233-89bc-8036-b680905bd1c4, rru,8ac58be0-a4dc-8343-f19f-62f15687bfc9, eutrancell,15072157-0659-35f3-8ec7-6dbf42846597, ant_cell,6e55cfa0-0ff2-4dbd-abe7-d467bfe0938e, rru_cell,92bf5f61-0267-bd9d-ea3c-7aa23f45aa59, aau_cell,05ee18b9-4464-e01b-3b87-eec3396372c7, eutrancell,d8aaafdd-69c9-8c6d-bfab-b6a4cf5ac344, rru_cell,f8bd6716-6fa1-b345-e4e3-6d691be4d4cb, rru,e994465b-6e1f-7723-8fdc-3c91f9fc1582, ant_cell,20e3541c-5a2d-ea0f-ffef-d047ea45e969, eutrancell,25492ebe-e55a-1292-6a80-4c7401fdb7ad, aau_cell,f7197e13-d4ec-755f-4826-e2d70b5cd2a1]

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AllenLeungX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值