objective c parse json from url request

前端 未结 7 1257
醉酒成梦
醉酒成梦 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:46

    Do this way:

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        // Append the new data to receivedData.
        // receivedData is an instance variable declared elsewhere.
    
        [responseData appendData:data];
    }
    
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSError *e = nil;
    NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:jsonData options: NSJSONReadingMutableContainers error: &e];
    
    }
    

提交回复
热议问题