objective c parse json from url request

前端 未结 7 1145
醉酒成梦
醉酒成梦 2021-02-06 00:14

I am trying to parse a json string requested from an api located at: http://www.physics.leidenuniv.nl/json/news.php

However, i am having trouble parsing this json. I get

7条回答
  •  南方客
    南方客 (楼主)
    2021-02-06 00:40

    Simple Way to store json-url data in dictionary.

     NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://query.yahooapis.com/v1/public/yql?q=select+%2A+from+weather.forecast+where+woeid%3D1100661&format=json"]];
        NSError *error=nil;
        id response=[NSJSONSerialization JSONObjectWithData:data options:
                     NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:&error];
    
        if (error) {
            NSLog(@"%@",[error localizedDescription]);
        } else {
            _query = [response objectForKey:@"query"];
            NSLog(@"%@",_query); 
    

    You can try this, so easy.

提交回复
热议问题