iOS可变json

时间:2014-06-19 18:32:59

标签: ios objective-c json

我正在尝试做一个收音机应用程序,我想从itunes获得专辑封面,即将完成但我需要一些帮助,我不知道如何让我的json请求每次歌曲更改时都会获取我的元数据变量,这是我在.m

中的代码
#import "EDViewController.h"
#define STREAM_URL @"http://4893.live.streamtheworld.com:80/ROCK_FMAAC_SC"
@interface EDViewController ()
@end
@implementation EDViewController
- (void)viewDidLoad {

radio = [[Radio alloc] init:@""];
[radio connect:STREAM_URL withDelegate:self withGain:(1.0)];
playing = YES;

[super viewDidLoad];;

NSMutableString *urlString = [NSMutableString stringWithFormat:@"https://itunes.apple.com/search?term"];

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

NSError *error;

NSMutableDictionary *artwork = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSMutableArray *results = [artwork objectForKey:@"results"];
NSDictionary *album = [results objectAtIndex:0];
NSString *artalbum = [album objectForKey:@"artworkUrl100"];

NSURL *urlOne = [NSURL URLWithString:artalbum];
NSData *newData = [NSData dataWithContentsOfURL:urlOne];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 69, 320, 325))];
[imageView setImage:[UIImage imageWithData:newData]];
[self.view addSubview:imageView];

UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:(CGRectMake(95, 167, 130, 130))];
[imageView2 setImage:[UIImage imageWithData:newData]];
[self.view addSubview:imageView2];
}
- (IBAction)play {
[radio resume];
}
- (IBAction)stop {
[radio updatePlay:NO];
}
- (IBAction)pause {
[radio pause];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
- (void)uodateBuffering:(BOOL)value {
NSLog(@"delegate update buffering %d", value);
}
- (void)interruptRadio {
NSLog(@"delegate radio interrupted");
}
- (void)resumeInterruptRadio {
NSLog(@"delegate resume interrupted Radio");
}
- (void)networkChanged {
NSLog(@"delegate network changed");
}
- (void)connectProblem {
NSLog(@"delegate connection problem");
}
- (void)audioUnplugged {
NSLog(@"delegate audio unplugged");
}
- (void)metaTitleUpdated:(NSString *)title {
NSLog(@"delegate title updated to %@", title);
NSArray *chunks = [title componentsSeparatedByString:@";"];
if ([chunks count]) {
    NSArray *streamTitle = [[chunks objectAtIndex:0] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"'-"]];
    if ([streamTitle count] > 1) {
        titleLabel.text = [streamTitle objectAtIndex:1];
    }
    NSArray *streamArtist = [[chunks objectAtIndex:0] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"'-"]];
    if ([streamArtist count] > 1) {
        test100.text = [streamArtist objectAtIndex:2];
    }
}
}
@end

正如您所看到的,我的元数据信息位于我的代码末尾,而我的json请求它几乎位于顶部。

0 个答案:

没有答案