顔認識 API である Lamda (https://www.mashape.com/lambda) と呼ばれる Mashape.com を介して API を使用しています。
認識リクエストから結果が返されると、「MashapeRespose」オブジェクトが返されます。
この MashapeResponse またはその一部を JSON オブジェクトに変換できません。
電話すると
NSLog(@"des=%@", [response body]);
これを印刷してもらいます
{
images = (
"http://api.lambdal.com/static/uploads/img05Xv8N.png"
);
photos = (
{
height = 241;
tags = (
{
attributes = (
{
confidence = "0.7097208087892503";
gender = male;
}
);
center = {
x = 95;
y = 98;
};
confidence = "0.978945010372561";
"eye_left" = {
x = 114;
y = 84;
};
"eye_right" = {
x = 76;
y = 85;
};
height = 112;
"mouth_center" = {
x = "96.5";
y = "134.5";
};
"mouth_left" = {
x = 74;
y = "134.5";
};
"mouth_right" = {
x = 119;
y = "134.5";
};
nose = {
x = 94;
y = 113;
};
tid = 31337;
uids = (
{
confidence = "0.323";
prediction = manuel;
uid = "manuel@MICClientele";
},
{
confidence = "0.194";
prediction = olivier;
uid = "olivier@MICClientele";
},
{
confidence = "0.161";
prediction = sean;
uid = "sean@MICClientele";
},
{
confidence = "0.161";
prediction = damien;
uid = "damien@MICClientele";
},
{
confidence = "0.065";
prediction = egle;
uid = "egle@MICClientele";
},
{
confidence = "0.065";
prediction = gareth;
uid = "gareth@MICClientele";
}
);
width = 112;
}
);
url = "http://api.lambdal.com/static/uploads/img05Xv8N.png";
width = 200;
}
);
status = success;
}
明らかに、これは有効な JSON ではありません。
MashapeResponse.h の内容は次のとおりです。
#import "MashapeResponse.h"
@interface MashapeResponse ()
@property (readwrite, retain) NSData* rawBody;
@property (readwrite) NSDictionary* headers;
@property (readwrite) int code;
@end
@implementation MashapeResponse
@synthesize rawBody;
@synthesize headers;
@synthesize code;
@synthesize body;
-(MashapeResponse*)initWithResponse:(int)httpCode headers:(NSDictionary*) httpHeaders rawBody:(NSData*) httpRawBody {
self = [super init];
[self setCode:httpCode];
[self setHeaders:httpHeaders];
[self setRawBody:httpRawBody];
return self;
}
@end
iOSでMashapeを使い、JSONオブジェクトに変換できた人はいますか?
部分文字列を使用して必要な情報を取得できますが、ドキュメントではjson応答である必要があるため、これは機能する方法ではありません..
控えめに言っても非常にイライラ...
よろしくダミアン
PS。この質問を Mashape サポートにメールしたので、誰かがここに回答を投稿する前に解決策が返ってきたら、この投稿に追加します。
編集:
電話すると
id status = [response valueForKey:@"status"];
NSLog(@"status=%@", [status description]);
id photos = [response valueForKey:@"photos"];
NSLog(@"photos=%@", [photos description]);
この例外が発生します
2012-09-20 16:53:20.609 Clientele[5160:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MashapeJsonObjectResponse 0x3d2810> valueForUndefinedKey:]: this class is not key value coding-compliant for the key status.'