maven 项目直接读取json字符串,然后取出其中数据

{
	"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字符串还没有过多研究,这种方式可以用而已

完整请参考:http://blog.maptoface.com/post/37

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Java中解析JSON字符串可以使用JSON库,例如Jackson、Gson、FastJSON等。这里以使用Jackson库为例,介绍如何解析JSON字符串。 假设有以下JSON字符串: ``` { "name": "Tom", "age": 25, "email": "tom@example.com", "address": { "city": "Beijing", "country": "China" }, "hobbies": ["reading", "swimming", "traveling"] } ``` 我们可以使用以下代码将其解析为Java对象: ```java import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static void main(String[] args) throws Exception { String jsonString = "{\n" + " \"name\": \"Tom\",\n" + " \"age\": 25,\n" + " \"email\": \"tom@example.com\",\n" + " \"address\": {\n" + " \"city\": \"Beijing\",\n" + " \"country\": \"China\"\n" + " },\n" + " \"hobbies\": [\"reading\", \"swimming\", \"traveling\"]\n" + "}"; ObjectMapper objectMapper = new ObjectMapper(); Person person = objectMapper.readValue(jsonString, Person.class); System.out.println(person); } } class Person { private String name; private int age; private String email; private Address address; private String[] hobbies; // 省略 getter 和 setter 方法 @Override public String toString() { return "Person{" + "name='" + name + '\'' + ", age=" + age + ", email='" + email + '\'' + ", address=" + address + ", hobbies=" + Arrays.toString(hobbies) + '}'; } } class Address { private String city; private String country; // 省略 getter 和 setter 方法 @Override public String toString() { return "Address{" + "city='" + city + '\'' + ", country='" + country + '\'' + '}'; } } ``` 在上面的代码中,我们使用Jackson库的ObjectMapper类将JSON字符串解析为Java对象。在Person类中定义了与JSON字符串对应的字段,而Address类则是Person类的一个成员变量。 可以看到,使用Jackson库解析JSON字符串非常方便,只需要将JSON字符串和对应的Java类传入ObjectMapper的readValue方法即可。同时,Jackson库也支持将Java对象转换为JSON字符串,具体操作可以查阅Jackson库的文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

全职计算机毕业设计

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

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

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

打赏作者

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

抵扣说明:

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

余额充值