JSON数组形式字符串转换为Map数组

package com.egb.bengfang.scheduled;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.egb.bengfang.common.GetCameraPreviewURL;
import com.egb.bengfang.web.domain.local.persistence.YsDataMapper;
import com.egb.bengfang.web.service.YsDataService;
import com.egb.bengfang.websocket.InfluxDBConnect;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service
@EnableScheduling
public class HealthScheduled {
    Logger logger = LoggerFactory.getLogger(HealthScheduled.class);
    @Autowired
    private YsDataMapper dataMapper;
    @Autowired
    private YsDataService ysDataService;
    @Scheduled(cron = "00 5/10 * * * ?")
    public void addMJDatas() {
        try {
            System.out.print("定时任务开始");
//            String result = GetCameraPreviewURL.GetCameraPreviewURL();
            String result ="{\n" +
                    "    \"code\": \"0\",\n" +
                    "    \"msg\": \"success\",\n" +
                    "    \"data\": {\n" +
                    "        \"total\": 1,\n" +
                    "        \"totalPage\": 1,\n" +
                    "        \"pageNo\": 1,\n" +
                    "        \"pageSize\": 100,\n" +
                    "        \"list\": [\n" +
                    "            {\n" +
                    "                \"eventId\": \"207dd3b1-37a7-4d6c-8e4d-c8bfd343051b\",\n" +
                    "                \"eventName\": \"acs.acs.eventType.successCard\",\n" +
                    "                \"eventTime\": \"2019-11-16T15:44:33+08:00\",\n" +
                    "                \"personId\": \"216e2ba145824269a1cbb423cdc85cb1\",\n" +
                    "                \"cardNo\": \"3891192334\",\n" +
                    "                \"personName\": \"sdk人员1zzzcb\",\n" +
                    "                \"orgIndexCode\": \"root000000\",\n" +
                    "                \"orgName\": \"默认组织\",\n" +
                    "                \"doorName\": \"10.40.239.69new_test2_门_1\",\n" +
                    "                \"doorIndexCode\": \"f0b50050d3434f15b4e34f885d5dacfe\",\n" +
                    "                \"doorRegionIndexCode\": \"fd2df06b-1afb-4c9b-b058-5740c2c00076\",\n" +
                    "                \"picUri\": \"no-pcnvr\",\n" +
                    "                \"svrIndexCode\": \"/pic?=d62i7f6e*6a7i125-c838b9--a8c67dea96e65icb1*=sd*=5dpi*=1dpi*m2i1t=4ed35444bb4s=-39\",\n" +
                    "                \"eventType\": 198914,\n" +
                    "                \"inAndOutType\": 1,\n" +
                    "                \"readerDevIndexCode\": \"378e563bf3e84d5ba6ef5742bbaa8933\",\n" +
                    "                \"readerDevName\": \"读卡器_1\",\n" +
                    "                \"devIndexCode\": \"dcff422aad9c4d60a47b8b2fe2757b71\",\n" +
                    "                \"devName\": \"10.40.239.69new_test2\",\n" +
                    "                \"identityCardUri\": \"/pic?=d62i7f6e*6a7i125-c838b9--a8c67dea96e65icb1*=sd*=5dpi*=1dpi*m2i1t=4ed35444bb4s=-39z422d3\",\n" +
                    "                \"receiveTime\": \"2019-11-16T15:45:13.525+08:00\",\n" +
                    "                \"jobNo\": \"23333\",\n" +
                    "                \"studentId\": \"201900001\",\n" +
                    "                \"certNo\": \"320826199012110005\"\n" +
                    "            }\n" +
                    "        ]\n" +
                    "    }\n" +
                    "}\n";
            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject jsonObject1 = JSON.parseObject(jsonObject.getString("data"));
            //jsonObject1.get("list");转换两遍json,获取data标签得list标签数据
            System.out.println(jsonObject1.get("list"));
            List> listObjectFir = (List>) JSONArray.parse(jsonObject1.get("list").toString());
            System.out.println("利用JSONArray中的parse方法来解析json数组字符串"+listObjectFir);
            ysDataService.addMJDatas(listObjectFir);
            System.out.print("定时任务结束");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

你可能感兴趣的:(java,spring,websocket)