2,462
社区成员
发帖
与我相关
我的任务
分享
{"time_used": 1203,
"thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101},
"confidence": 90.662,
"request_id": "1498464734,bfc27199-17f8-437c-86f5-290a0816d0c3"}
With ScriptControl1
.Reset
.Language = "javascript"
.AddCode "var json = " & strFaceJSON & ";"
'获取三个参数的值
txtConfidence = .Eval("json.confidence")
txtTimeUsed = .Eval("json.time_used")
txtRequest_id = .Eval("json.request_id")
'thresholds或1e-3,1e-5,1e-4如何获取?
'
txtTemp = .Eval("thresholds") '只返回 [object object] 真是愁人 真是愁人 真是愁人
End Sub
"attributes": {
"gender": {
"value": "Female"
},
"age": {
"value": 21
},
"headpose": {
"yaw_angle": -26.625063,
"pitch_angle": 12.921974,
"roll_angle": 22.814377
},
"smile": {
"threshold": 30.1,
"value": 2.566890001296997
}
},
"face_rectangle": {
"width": 140,
"top": 89,
"left": 104,
"height": 141
}
已知,获取left值,可以这样写:
.Eval("json.faces[0].face_rectangle['left']")
那么,如何获取attributes的age值和smile的threshold值?烦请指导。{
"faces1": [{"face_rectangle": {"width": 367, "top": 259, "left": 155, "height": 367}, "face_token": "6b9486d1b6e77b682eeffc047b6de139"}],
"faces2": [{"face_rectangle": {"width": 168, "top": 184, "left": 298, "height": 168}, "face_token": "eca652ec453660f7b2a6f60668a4fbfd"}],
"time_used": 1203,
"thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101},
"confidence": 90.662,
"request_id": "1498464734,bfc27199-17f8-437c-86f5-290a0816d0c3"}
发完一楼帖子后,得到了圆满解决。
现在要获取的是 "faces2" 的 face_rectangle值,即{"width": 168, "top": 184, "left": 298, "height": 168}这个字符串,只要得到这个字符串,就可以分割获得width,top,left,height,此为后话。
JSONParse("faces2[0].face_rectangle['left']", Str)
JSONParse("faces2[0].face_rectangle['top']", Str)
JSONParse("faces2[0].face_rectangle['width']", Str)
JSONParse("faces2[0].face_rectangle['height']", Str)
Public Function JSONParse(ByVal JSONPath As String, ByVal JSONString As String) As Variant
Dim JSON As Object
Set JSON = CreateObject("MSScriptControl.ScriptControl")
JSON.Language = "JScript"
JSONParse = JSON.eval("JSON=" & JSONString & ";JSON." & JSONPath & ";")
Set JSON = Nothing
End Function
Public Sub main()
Dim Str As String
Str = "{""time_used"": 1203,""thresholds"": {""1e-3"": 62.327, ""1e-5"": 73.975, ""1e-4"": 69.101},""confidence"": 90.662,""request_id"": ""1498464734,bfc27199-17f8-437c-86f5-290a0816d0c3""}"
Debug.Print JSONParse("thresholds['1e-3']", Str)
Debug.Print JSONParse("thresholds['1e-5']", Str)
Debug.Print JSONParse("thresholds['1e-4']", Str)
End Sub