Suporte do The Movie Database

I am working on my first iOS app and I'm also new to using an API. I'm trying to figure out how to access data through the API.

  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // create the URL we'd like to query NSURL myURL = [[NSURL alloc]initWithString:@"http://api.themoviedb.org/3/movie/550?api_key="];

                // we'll receive raw data so we'll create an NSData Object with it
                NSData *myData = [[NSData alloc]initWithContentsOfURL:myURL];
    
                // now we'll parse our data using NSJSONSerialization
                id myJSON = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:nil];
    
                // typecast an array and list its contents
                NSArray *jsonArray = (NSArray *)myJSON;
    
                // take a look at all elements in the array
                for (id element in jsonArray) {
                    NSLog(@"Element: %@", [element description]);
                }
    

    }

That's the code I am currently using (with an API key filled in of course). When I run this code I get things like "Element: release_date". How do I access the actual release date, the data associated with release_date?

2 respostas (na página 1 de 1)

Jump to last post

Hi nevrothwen,

I haven't taken a look at the data returned by the API yet, so I can be specific until I have done so. However, you want to be looking at using the valueForKey: method on the array.

NSString *releaseDate = [jsonArray valueForKey:@"releasedate"];

That should get you the release date?

Thanks. I managed to figure it out after a while. Still trying to get my head around JSON and such :-)

Não consegue encontrar um certo filme ou série? Inicie sessão e adicione-o.

Geral

s focus the search bar
p abrir menu do perfil
esc close an open window
? open keyboard shortcut window

Em páginas de Média

b go back (or to parent when applicable)
e ir para a página de edição

Em páginas de temporadas de séries

(seta para a direita) ir para a próxima temporada
(seta para a esquerda) ir para a temporada anterior

Em Páginas de Episódios de Séries

(seta para a direita) ir para o próximo episódio
(seta para a esquerda) ir para o episódio anterior

Em Todas as Páginas de Imagens

a abrir janela para adicionar imagem

Em Todas as Páginas de Edição

t open translation selector
ctrl+ s submit form

Em Páginas de Discussão

n criar uma nova discussão
w toggle watching status
p toggle public/private
c toggle close/open
a abrir actividade
r reply to discussion
l ir para a última resposta
ctrl+ enter submit your message
(seta para a direita) página seguinte
(seta para a esquerda) página anterior

Definições

Deseja classificar ou adicionar este item a uma lista?

Iniciar Sessão

Ainda não é um membro?

Crie uma Conta e Adere a Comunidade