ios - Mashape Objective-C for iOS - 对 JSON 对象的 MashapeResponse
<p><p>我正在通过 Mashape.com 使用一个名为 Lamda (https://www.mashape.com/lambda) 的人脸识别 API。</p>
<p>当我从识别请求中获取结果时,它会给我一个“MashapeRespose”对象。</p>
<p>我无法将此 MashapeResponse 或其任何部分转换为 JSON 对象。</p>
<p>当我打电话时</p>
<pre><code>NSLog(@"des=%@", );
</code></pre>
<p>我把这个打印出来</p>
<pre><code>{
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;
}
</code></pre>
<p>显然这不是有效的 JSON。 </p>
<p>这是 MashapeResponse.h 的内容</p>
<pre><code>#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 = ;
;
;
;
return self;
}
@end
</code></pre>
<p>有没有人能够在 iOS 上使用 Mashape 并能够转换成 JSON 对象?</p>
<p>我可以使用子字符串来获取我想要的信息,但这不是它应该如何工作,因为文档声明它应该是一个 json 响应..</p>
<p>至少可以说非常沮丧......</p>
<p>问候
达米安</p>
<p>PS。我已经向 Mashape 支持发送了这个问题,所以如果我在有人在这里发布答案之前得到解决方案,我会将其添加到这篇文章中。</p>
<p>编辑:</p>
<p>当我打电话时</p>
<pre><code>id status = ;
NSLog(@"status=%@", );
id photos = ;
NSLog(@"photos=%@", );
</code></pre>
<p>我得到了这个异常</p>
<pre><code>2012-09-20 16:53:20.609 Clientele *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MashapeJsonObjectResponse 0x3d2810> valueForUndefinedKey:]: this class is not key value coding-compliant for the key status.'
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>首先感谢 Dcritelli 对这个问题的帮助..</p>
<p>我收到了 Mashape 对我的问题的回复,他们向我发送了这封电子邮件作为回复。</p>
<hr/>
<blockquote>
<p>Hi Damien,</p>
<p>The method already returns a parsed JSON object. If
you need the raw response in bytes (that is a NSData* object), you can
get it by invoking . You can convert a NSData* to
NSString* if you want.</p>
<p>Given that returns the parsed JSON object, for example
to get the "url" property of the first photo in the "photos" array,
you would write:</p>
</blockquote>
<pre><code> NSArray* photos = [ objectForKey:@"photos"];
NSDictionary* firstPhoto = ;
NSString* url = ;
NSLog(@"URL of the first photo is: %@", url);
</code></pre>
<blockquote>
<p>We apologize if the docs were confusing, we updated them and you can
read the new revision here:
<a href="https://www.mashape.com/docs/consume/objectivec" rel="noreferrer noopener nofollow">https://www.mashape.com/docs/consume/objectivec</a></p>
<p>Let us know if you need additional help, Cheers</p>
</blockquote>
<hr/>
<p>因此,他们不仅回复了解决方案,还更新了文档。</p>
<p>向 Mashape 致敬。</p>
<p>问候
达米安</p></p>
<p style="font-size: 20px;">关于ios - Mashape Objective-C for iOS - 对 JSON 对象的 MashapeResponse,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/12514977/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/12514977/
</a>
</p>
页:
[1]