2

所以我有一个 JavaScript 应用程序,它拍摄用户照片,然后将其发送到人脸识别 API,它返回一个 JSON 值,然后我将其转换为字符串。但是我只有返回给我的两个项目是重要的。我想将这两个(uid和confidence)拉出来并将它们设置为变量;我不完全确定该怎么做。以下是返回内容的示例:

{"photos":[{"url":"http://api.skybiometry.com/fc/images/get?id=bmN2X3hybD0wMTk5c29ub3I0MXE0bjN…RyMTQzJmVxPTE1ODkmY3ZxPTY5MjcxMzEyMTI3cTImZ3Z6cmZnbnpjPTIwMTMwNDE0MTgxNjI5","pid":"F@0deeecd9274c7d8357343ed57e6aaf6c_69271312127d2","width":380,"height":300,"tags":[{"tid":"TEMP_F@0deeecd9274c7d8357343ed500c20089_69271312127d2_51.05_45.67_0_1","recognizable":true,"threshold":20,"uids":[{"uid":"sam@sam","confidence":100}],"confirmed":false,"manual":false,"width":20,"height":25.33,"center":{"x":51.05,"y":45.67},"eye_left":{"x":56.32,"y":39.67},"eye_right":{"x":46.32,"y":40},"mouth_center":{"x":48.68,"y":55.67},"nose":{"x":50.79,"y":47},"yaw":0,"roll":1,"pitch":0,"attributes":{"face":{"value":"true","confidence":60}}}]}],"status":"success","usage":{"used":5,"remaining":95,"limit":100,"reset_time_text":"Sun, 14 April 2013 18:20:53 +0000","reset_time":1365963653}} 

这是我目前用来返回整个字符串的代码:

.done(function (result) {
    alert("Received response..");
    var resultObject = JSON.stringify(result);
    alert(resultObject);
});

任何帮助是极大的赞赏!

4

1 回答 1

4
 .done(function (result) {
     if(result != null) {
        var uids = result.photos[0].tags[0].uids[0]; 
        var uid = uids.uid; 
        var confidence = uids.confidence; 

     } });
于 2013-04-14T18:50:48.790 回答