How to parse a KairosSDK JSON response in Swift?

For those who don't know what the Kairos SDK is, it is basically a face recognition api.

When you give it an image, it will tell you who, if they can match you to someone from the database.

When I give him a picture; api sends me a response:

[images: (
    {
    attributes =         {
        gender =             {
            confidence = "80%";
            type = F;
        };
    };
    candidates =         (
                    {
            "enrollment_timestamp" = 1436883322;
            face3rd = "0.988351106643677";
        },
                    {
            "enrollment_timestamp" = 1436883214;
            hi = "0.94137054681778";
        },
                    {
            "enrollment_timestamp" = 1436883132;
            hi = "0.94137054681778";
        }
    );
    time = "6.43676";
    transaction =         {
        confidence = "0.988351106643677";
        "distance_apart" = "0.046980559825897";
        "gallery_name" = test1;
        height = 482;
        "matching_threshold" = "0.4";
        "next_subject" = hi;
        "next_subject_confidence" = "0.94137054681778";
        "simularity_threshold" = "0.1";
        status = success;
        subject = face3rd;
        topLeftX = 148;
        topLeftY = 92;
        width = 482;
    };
}
)]

      

What I did is put three images into the database and call each one accordingly, face3rd, hello, hello (sorry for the two hello)

I'm trying to parse the names and the number next to it for soo long, I can get around the 6 second response time.

The reason I couldn't get the names is because, as you can see, I don't know what to tell Swift to look for. The title of the image changes depending on who I return with.

I don't know if I explained my situation correctly, but if you look at the answer. The parts that say:

face3rd = "0.988351106643677";
hi = "0.94137054681778";
hi = "0.94137054681778";

      

I need information on both sides of the equal sign.

Thank you for your help and apologize if the reading was pedantic or if you felt there was a lot of repetition.

Thank!

+3


source to share


1 answer


Yes, this is poorly formatted JSON that we are returning. We will fix it in an upcoming version of the API (there is currently no release date.).

If all you want is the closest match, you can simply access the subject variable directly and ignore the candidate array.



Otherwise, you will need to manually parse the candidate array. I'm not sure how to do this in Swift.

0


source







All Articles