在ios jsonparsing问题中获取方法

我只是想打url: http : /city_id/1 ,参数是city_id.ie:/ /city_id/1但是; 编译器创build错误

 Domain=NSURLErrorDomain Code=-1002 "unsupported URL" or error 300; 

那么在目标c中的方法中传递参数的最好方法是什么?它也会导致Error Domain=kCFErrorDomainCFNetwork Code=303 “操作无法完成。

 (kCFErrorDomainCFNetwork error 303 

如果有人能尽快答复,我将很高兴。

无法重现您提到的问题,可能问题不是因为您使用的URL或参数。

这是处理GET Web服务调用和parsing来自响应的数据的最好方法之一,在这里我使用URL和params实现了Web调用,

 // 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; } 

jsonObjparsing的响应forms为 在这里输入图像说明