Application of string segmentation, stream, JSONObject, and lambda expressions

Requirement: Split the data corresponding to the state field and obtain the first number as the status. 0 represents offline and 1 represents online
The following is the returned data, in which the state data is not What we want:

{
    
    
    "status": "200",
    "message": "success",
    "error": null,
    "path": null,
    "timestamp": "2021-06-01 13:39:31",
    "data": [
        {
    
    
            "dateTime": null,
            "lng": "0E-12",
            "detailId": "13011000010010886016",
            "state": "01",
            "describe": "13011000010010886016",
            "title": "北门人行出口14",
            "lat": "0E-12"
        },
        {
    
    
            "dateTime": null,
            "lng": "0E-12",
            "detailId": "13011000010010886017",
            "state": "10",
            "describe": "13011000010010886017",
            "title": "西门人行进口12",
            "lat": "0E-12"
        }]
        }

Controller layer processing:

 @GetMapping("/video/list")
    @ApiOperation("视频图层列表")
    public Result getVideoList(){
    
    
        LayerQo qo = new LayerQo();
        // layerId=1代表视频图层
        qo.setLayerId(LayerEnum.VEDIO_LAYER.getLayerId());
        //将state的12->1  截取第一位数字,作为状态
        List<JSONObject> list = ((List<Object>)iPublicFeignClientService.getVedioLayerPost(qo).getData()).stream().map(obj ->{
    
    
            JSONObject json = (JSONObject) JSONObject.toJSON(obj);
            json.put("state",json.getString("state").substring(0,1));
            return json;
        }).collect(Collectors.toList());
        return GovernResult.ok(list);
    }

Then, the data returned is:

{
    
    
    "status": "200",
    "message": "success",
    "error": null,
    "path": null,
    "timestamp": "2021-06-01 13:39:31",
    "data": [
        {
    
    
            "dateTime": null,
            "lng": "0E-12",
            "detailId": "13011000010010886016",
            "state": "0",
            "describe": "13011000010010886016",
            "title": "北门人行出口14",
            "lat": "0E-12"
        },
        {
    
    
            "dateTime": null,
            "lng": "0E-12",
            "detailId": "13011000010010886017",
            "state": "1",
            "describe": "13011000010010886017",
            "title": "西门人行进口12",
            "lat": "0E-12"
        }]
        }

Record the code that I have been working on for a long time, knowledge points:
String segmentation, stream, JSONObject application

おすすめ

転載: blog.csdn.net/victo_chao/article/details/117441382