ios - 如何阅读json字典

标签 ios json

我必须读取 json 数据但没有获取 .mp3 文件我不知道如何获取它请帮助我

我的代码是

 NSArray *ar = [NSArray arrayWithObject:[dict objectForKey:@"pronunciations"]];
 for (NSString *key in [dict objectForKey:@"pronunciations"])
 {
     for (NSDictionary *dictpro in ar)
     {
         NSLog(@"key2   is %@",key);
         NSLog(@"title for key2 is %@",[dict objectForKey:key] );
     }
 }

响应是 key2 是

{
   audio =    
   (
       {
           type = pronunciation;
           url = "/v2/dictionaries/assets/ldoce/gb_pron/abate0205.mp3";
       }
   );

   ipa = "\U0259\U02c8be\U026at";
}

2013-11-30 10:53:37.756 TestJson[419:c07] title for key2 is (null)

我必须阅读 .mp3 文件,请帮助我。

最佳答案

知道了, 执行以下操作

NSDictionary *dictResult = [JSONRepsponse objectForKey:@"result"];
NSDictionary *dictPronunciations = [dictResult valueForKey:@"pronunciations"];
NSDictionary *dictAudio = [dictPronunciations valueForKey:@"audio"];
NSString *strMp3Path = [dictAudio valueForKey:@"url"];
NSString *commonUrl = @"https://api.pearson.com";
NSString *strUrl = [commonUrl stringByAppendingString:strMp3Path];
NSURL *url =  [NSURL URLWithString:[strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *dataMp3 = [NSData dataWithURL : url];

您可以使用此数据在 AvAudio Player 中播放 Mp3

关于ios - 如何阅读json字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20296952/

相关文章:

iphone - NSInvalidArgumentException,原因 : 'Invalid type in JSON write (__NSDate)'

iphone - 使用GCD加速 View 的加载

ios - 使用 HCYoutubeParser 播放 YouTube 视频

ios - AFNetworking 2.0 实现代码不起作用

ios - Restkit — 如何映射具有可变键名的 json 对象

javascript - Backbone 101 - 在主干中使用 JSON 数据

json - 在 Ubuntu 上将 jq 升级到 1.5

ios - 如果/否则基于数组中对象的存在?

objective-c - 自定义 UIView 和 becomeFirstResponder

json - Alamofire:通过成功响应处理错误