nsjsonserialization - Xcode 7 Json Fetching always crashing -
whenever trying fetch data through json in xcode 7 giving me error :
terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'data parameter nil' in xcode 6 working fine. new method has been implemented in xcode 7 fetch data json .
[nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139"]]; id response=[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments error:nil];
nserror *error; nsurl *url = [nsurl urlwithstring:@"http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139"]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url]; [request sethttpmethod:@"get"]; [request setvalue:@"application/json" forhttpheaderfield:@"content-type"]; nsdata *data = [nsurlconnection sendsynchronousrequest:request returningresponse: nil error:&error]; if (!data) { nslog(@"download error: %@", error.localizeddescription); } // parsing json data received web service nsdictionary object nsdictionary *json = [nsjsonserialization jsonobjectwithdata: data options: nsjsonreadingmutablecontainers error: &error]; try working
Comments
Post a Comment