maven 项目直接读取json字符串,然后取出其中数据
程序员文章站
2024-01-10 09:47:04
...
{
"image_id": "iOphreMMOUFIwzPsybKuNA==",
"request_id": "1531448780,f00cd38a-59df-4850-8a11-f475448d1484",
"time_used": 267,
"faces": [{
"landmark": {
"mouth_upper_lip_left_contour2": {
"y": 148,
"x": 91
},
"mouth_upper_lip_top": {
"y": 146,
"x": 103
},
"mouth_upper_lip_left_contour1": {
"y": 145,
"x": 98
},
"left_eye_upper_left_quarter": {
"y": 97,
"x": 72
},
"left_eyebrow_lower_middle": {
"y": 82,
"x": 73
},
"mouth_upper_lip_left_contour3": {
"y": 152,
"x": 94
},
"right_eye_top": {
"y": 95,
"x": 126
},
"left_eye_bottom": {
"y": 103,
"x": 77
},
"right_eyebrow_lower_left_quarter": {
"y": 82,
"x": 122
},
"right_eye_pupil": {
"y": 99,
"x": 125
},
"mouth_lower_lip_right_contour1": {
"y": 152,
"x": 111
},
"mouth_lower_lip_right_contour3": {
"y": 159,
"x": 109
},
"mouth_lower_lip_right_contour2": {
"y": 156,
"x": 115
},
"contour_chin": {
"y": 185,
"x": 102
},
"contour_left9": {
"y": 183,
"x": 88
},
"left_eye_lower_right_quarter": {
"y": 102,
"x": 82
},
"mouth_lower_lip_top": {
"y": 152,
"x": 103
},
"right_eyebrow_upper_middle": {
"y": 78,
"x": 130
},
"left_eyebrow_left_corner": {
"y": 84,
"x": 59
},
"right_eye_bottom": {
"y": 103,
"x": 126
},
"contour_left7": {
"y": 168,
"x": 68
},
"contour_left6": {
"y": 159,
"x": 61
},
"contour_left5": {
"y": 148,
"x": 56
},
"contour_left4": {
"y": 136,
"x": 53
},
"contour_left3": {
"y": 124,
"x": 51
},
"contour_left2": {
"y": 113,
"x": 49
},
"contour_left1": {
"y": 100,
"x": 49
},
"left_eye_lower_left_quarter": {
"y": 102,
"x": 72
},
"contour_right1": {
"y": 101,
"x": 156
},
"contour_right3": {
"y": 125,
"x": 154
},
"contour_right2": {
"y": 113,
"x": 156
},
"mouth_left_corner": {
"y": 153,
"x": 85
},
"contour_right4": {
"y": 137,
"x": 152
},
"contour_right7": {
"y": 170,
"x": 137
},
"right_eyebrow_left_corner": {
"y": 81,
"x": 114
},
"nose_right": {
"y": 130,
"x": 116
},
"nose_tip": {
"y": 124,
"x": 102
},
"contour_right5": {
"y": 149,
"x": 149
},
"nose_contour_lower_middle": {
"y": 134,
"x": 101
},
"left_eyebrow_lower_left_quarter": {
"y": 83,
"x": 66
},
"mouth_lower_lip_left_contour3": {
"y": 160,
"x": 95
},
"right_eye_right_corner": {
"y": 100,
"x": 135
},
"right_eye_lower_right_quarter": {
"y": 102,
"x": 131
},
"mouth_upper_lip_right_contour2": {
"y": 148,
"x": 114
},
"right_eyebrow_lower_right_quarter": {
"y": 84,
"x": 137
},
"left_eye_left_corner": {
"y": 100,
"x": 68
},
"mouth_right_corner": {
"y": 152,
"x": 119
},
"mouth_upper_lip_right_contour3": {
"y": 152,
"x": 111
},
"right_eye_lower_left_quarter": {
"y": 102,
"x": 121
},
"left_eyebrow_right_corner": {
"y": 81,
"x": 88
},
"left_eyebrow_lower_right_quarter": {
"y": 82,
"x": 81
},
"right_eye_center": {
"y": 99,
"x": 126
},
"nose_left": {
"y": 130,
"x": 86
},
"mouth_lower_lip_left_contour1": {
"y": 152,
"x": 94
},
"left_eye_upper_right_quarter": {
"y": 97,
"x": 83
},
"right_eyebrow_lower_middle": {
"y": 83,
"x": 130
},
"left_eye_top": {
"y": 95,
"x": 77
},
"left_eye_center": {
"y": 100,
"x": 77
},
"contour_left8": {
"y": 176,
"x": 77
},
"contour_right9": {
"y": 183,
"x": 116
},
"right_eye_left_corner": {
"y": 101,
"x": 117
},
"mouth_lower_lip_bottom": {
"y": 160,
"x": 102
},
"left_eyebrow_upper_left_quarter": {
"y": 79,
"x": 65
},
"left_eye_pupil": {
"y": 99,
"x": 78
},
"right_eyebrow_upper_left_quarter": {
"y": 78,
"x": 122
},
"contour_right8": {
"y": 178,
"x": 127
},
"right_eyebrow_right_corner": {
"y": 86,
"x": 145
},
"right_eye_upper_left_quarter": {
"y": 97,
"x": 121
},
"left_eyebrow_upper_middle": {
"y": 76,
"x": 73
},
"right_eyebrow_upper_right_quarter": {
"y": 80,
"x": 139
},
"nose_contour_left1": {
"y": 102,
"x": 93
},
"nose_contour_left2": {
"y": 122,
"x": 90
},
"mouth_upper_lip_right_contour1": {
"y": 145,
"x": 107
},
"nose_contour_right1": {
"y": 102,
"x": 110
},
"nose_contour_right2": {
"y": 122,
"x": 113
},
"mouth_lower_lip_left_contour2": {
"y": 157,
"x": 89
},
"contour_right6": {
"y": 160,
"x": 144
},
"nose_contour_right3": {
"y": 133,
"x": 109
},
"nose_contour_left3": {
"y": 132,
"x": 94
},
"left_eye_right_corner": {
"y": 101,
"x": 87
},
"left_eyebrow_upper_right_quarter": {
"y": 77,
"x": 81
},
"right_eye_upper_right_quarter": {
"y": 96,
"x": 131
},
"mouth_upper_lip_bottom": {
"y": 152,
"x": 103
}
},
"attributes": {
"emotion": {
"sadness": 1.698,
"neutral": 72.033,
"disgust": 0.033,
"anger": 0.033,
"surprise": 25.961,
"fear": 0.033,
"happiness": 0.21
},
"beauty": {
"female_score": 56.061,
"male_score": 56.356
},
"gender": {
"value": "Female"
},
"age": {
"value": 30
},
"mouthstatus": {
"close": 99.974,
"surgical_mask_or_respirator": 0.0,
"open": 0.026,
"other_occlusion": 0.0
},
"glass": {
"value": "None"
},
"skinstatus": {
"dark_circle": 4.106,
"stain": 4.536,
"acne": 1.67,
"health": 71.893
},
"headpose": {
"yaw_angle": 2.7330384,
"pitch_angle": -0.86606795,
"roll_angle": 1.2214376
},
"blur": {
"blurness": {
"threshold": 50.0,
"value": 0.337
},
"motionblur": {
"threshold": 50.0,
"value": 0.337
},
"gaussianblur": {
"threshold": 50.0,
"value": 0.337
}
},
"smile": {
"threshold": 50.0,
"value": 0.063
},
"eyestatus": {
"left_eye_status": {
"normal_glass_eye_open": 0.082,
"no_glass_eye_close": 0.0,
"occlusion": 0.0,
"no_glass_eye_open": 99.918,
"normal_glass_eye_close": 0.0,
"dark_glasses": 0.0
},
"right_eye_status": {
"normal_glass_eye_open": 0.113,
"no_glass_eye_close": 0.0,
"occlusion": 0.0,
"no_glass_eye_open": 99.887,
"normal_glass_eye_close": 0.0,
"dark_glasses": 0.0
}
},
"facequality": {
"threshold": 70.1,
"value": 93.341
},
"ethnicity": {
"value": "ASIAN"
},
"eyegaze": {
"right_eye_gaze": {
"position_x_coordinate": 0.456,
"vector_z_component": 0.985,
"vector_x_component": -0.141,
"vector_y_component": 0.097,
"position_y_coordinate": 0.441
},
"left_eye_gaze": {
"position_x_coordinate": 0.508,
"vector_z_component": 0.991,
"vector_x_component": 0.112,
"vector_y_component": 0.068,
"position_y_coordinate": 0.43
}
}
},
"face_rectangle": {
"width": 110,
"top": 76,
"left": 47,
"height": 110
},
"face_token": "3e02996adf04664447a9d7ce44d2ad25"
}]
}
json数据如上
需要直接读取然后显示数据
//返回json数据
String jsonString=DetectApi.detect(filePath+fileName);
//json数据处理,具体需要看格式
JSONObject jsStr = JSONObject.fromObject(jsonString);
JSONArray faces=jsStr.getJSONArray("faces");
JSONObject mid=faces.getJSONObject(0);
Map<String, Object> landmark=(Map)mid.get("landmark");
Map<String, Object> right_eye_left_corner=(Map)landmark.get("right_eye_left_corner");
Map<String, Object> right_eye_right_corner=(Map)landmark.get("right_eye_right_corner");
Map<String, Object> right_eye_top=(Map)landmark.get("right_eye_top");
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
这是依赖,网上不太好找到。
总结:直接读取json字符串还没有过多研究,这种方式可以用而已