diff --git a/BaiduAIFaceDetection b/BaiduAIFaceDetection index 6dfd68d..87e5b8d 100644 Binary files a/BaiduAIFaceDetection and b/BaiduAIFaceDetection differ diff --git a/BaiduAIFaceDetection.c b/BaiduAIFaceDetection.c index 50f0030..4af1877 100644 --- a/BaiduAIFaceDetection.c +++ b/BaiduAIFaceDetection.c @@ -2,7 +2,7 @@ #include #include #include -#include "cJSON.h" +#include #include #include #include @@ -65,7 +65,34 @@ size_t faceMatch_callback(void *ptr, size_t size, size_t nmemb, void *stream) strncpy(buf, ptr, size * nmemb); cJSON *json = cJSON_Parse(buf); - printf("data:%s\n", cJSON_Print(json)); + + cJSON *result = cJSON_GetObjectItem(json, "result"); + cJSON *face_list = cJSON_GetObjectItem(result, "face_list"); + + + // 数组 + int skill_array_size = cJSON_GetArraySize(face_list); + for (int i = 0; i < skill_array_size; i++) { + cJSON *cjson_skill_item = cJSON_GetArrayItem(face_list, i); + //printf("%s\n", cJSON_Print(cjson_skill_item)); + cJSON *age = cJSON_GetObjectItem(cjson_skill_item, "age"); + printf("年龄: %s\n", cJSON_Print(age)); + + cJSON *gender = cJSON_GetObjectItem(cjson_skill_item, "gender"); + cJSON *type = cJSON_GetObjectItem(gender, "type"); + if (0 == strcmp(type->valuestring, "female")) + { + printf("性别: 女性\n"); + } + else + { + printf("性别: 男性\n"); + } + cJSON *beauty = cJSON_GetObjectItem(cjson_skill_item, "beauty"); + printf("美丽值: %s\n", cJSON_Print(beauty)); + + } + if (strstr(cJSON_Print(json), "SUCCESS") == NULL) { *((double *)stream) = 0; } else { @@ -99,7 +126,7 @@ int post_faceMatch(char *access_token, char *file) curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_POST, 1); struct curl_slist *headers = NULL; - headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8"); + headers = curl_slist_append(headers, "Content-Type: application/json;charset=UTF-8"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cJSON_Print(json)); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, faceMatch_callback);