0

Como puedo obtener los datos un JSON desde un URL.

Mi JSON

{"artist":"\u200bblackbear","song":"\u200bhot girl bummer","album_art":"https://images.genius.com/b16820e87772d7ba462bc4a9b3021338.1000x1000x1.png","lyrics":"\n \n \n This that college dropout music\nEvery day leg day, she be too thickAnd my friends are all annoying\nBut we go dumb, yeah, we go stupidThis that college dropout music\nEvery day leg day, she be too thickAnd my friends are all annoying\nBut we go dumb, yeah, we go stupid\nWe go stupid, we go stupid, we go\u2014And you want me to change? Fuck you!\n[Chorus]Fuck you, and you, and you\nI hate your friends and they hate me tooI'm through, I'm through, I'm through"}

El URL

NSURL *URL = [NSURL URLWithString:lyrURL];

Lo que más me interesa es lyrics

1 respuesta 1

0
NSString *url = [NSString stringWithFormat: @"https://google.com/?q=%@",query];
NSHTTPURLResponse *coderesponse = nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:url]
                          cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                          timeoutInterval:10];

NSData* response = [NSURL sendSynchronousRequest:request returningResponse:&coderesponse error:nil];

Finalmente lo podemos almacenar en una variable

lyr = [[NSJSONSerialization JSONObjectWithData:response options: kNilOptions error:Nil] objectForKey:@"lyrics"];

EDITADO:
Validación en caso que nos entregue nil (null):

if(coderesponse){    //Si nos da respuesta (no nil) entonces almacenamos                                                         
lyr = [[NSJSONSerialization JSONObjectWithData:response options: kNilOptions error:Nil] objectForKey:@"lyrics"];                         
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.