Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

get method in ios json parsing issue

I just want to hit URL : http://kiascenehai.pk/rest_api/todayEvents/api-key/Of7NU7Jimh665D5G5VwO2eKO69sWv9lf/format/json and parameter is city_id.i.e: /city_id/1 but; compiler creates Error

Domain=NSURLErrorDomain Code=-1002

 "unsupported URL"

 or
 error 300;

so what shall be best way to pass arguments in a method in objective c???it also causes Error Domain=kCFErrorDomainCFNetwork Code=303 "The operation couldn’t be completed.

(kCFErrorDomainCFNetwork error 303

It will be pleasure for me if any one can reply me fast as possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unable to reproduce issue you have mentioned, Probably the issue 'll be not because of the URL or parameters you used.

This is one of the best way to handle GET web service call and parsing data from the response, here i implemented the web call with your URL and params,

// Server data fetch
- (void)getDataForCityId:(NSInteger)cityId
{
    NSMutableString *urlString = [@"http://kiascenehai.pk/rest_api/todayEvents/api-key/Of7NU7Jimh665D5G5VwO2eKO69sWv9lf/format/json/city_id/" mutableCopy];
    [urlString appendFormat:@"%d", cityId];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];
    [request setHTTPMethod:@"GET"];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
         if (data)
         {
             id jsonObj = [self parseJSON:data];
         }
     }];
}

// Method parses the JSON Data Received
- (id)parseJSON:(NSData *)data
{
    id jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
    return jsonData;
}

The jsonObj parsed form the response is asenter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...