मैं गूगल भाषण मान्यता API का उपयोग किया है और मैं एक json प्रतिक्रिया जो सीधे iOS पर parsable नहीं था हो रही थी। परिणाम नमूने इस तरह थे:
सबसे पहले मैंने हैलो 1 2 3 कहने की कोशिश की जो मुद्दों के बिना पहचाना गया था। Json प्रतिक्रिया थी:
{"result":[]}
{"result":[{"alternative":[{"transcript":"hello 123","confidence":0.59780568},{"transcript":"hello 1 2 3"}],"final":true}],"result_index":0}
या जब भी लंबे समय के लिए बात की थी, मैं नीचे की तरह एक 404 एचटीएमएल मिला:
<html><title>Error 400 (Bad Request)!!1</title></html>
और जब मैं निरर्थक शब्दों में बात की थी, मुझे मिल गया:
{"result":[]}
तो इस तरह की सभी प्रतिक्रियाओं का विश्लेषण करने के लिए, मैंने नीचे दिए गए कोड का उपयोग किया:
NSString *msg = @"Could not synthesize !";
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"responseString: %@",responseString);
if([responseString containsString:@"transcript"]&&responseString.length>25)
{
responseString = [responseString stringByReplacingOccurrencesOfString:@"{\"result\":[]}" withString:@""];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
if(dictionary!=nil)
if(dictionary.allValues.count>0)
{
NSArray *array =[dictionary valueForKeyPath:@"result.alternative.transcript"];
if(array)
{
NSArray *array2 = [array objectAtIndex:0];
if(array2)
{
NSLog(@"%@",[array2 objectAtIndex:0]);
msg = [array2 objectAtIndex:0];
};
}
}
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Google Response" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
उम्मीद है कि यह किसी की मदद करता है।
स्रोत
2014-12-17 11:02:15
[आपने क्या प्रयास किया है?] (Http://mattgemmell.com/2008/12/08/what-have-you-tried/) – vikingosegundo