IOS 'NSInternalInconsistencyException'

來源:互聯網
上載者:User

標籤:span   message   rar   地方   sar   好的   http   城市   com   

今天想寫一個請求的天氣。好的。廢話不多說。先貼代碼:

使用AFNetWorking 發送get請求,可是一直報錯  IOS ‘NSInternalInconsistencyException‘, reason: ‘Invalid parameter not satisfying: URLString‘  

翻譯出來就是  不能滿足urlstring。 可能時請求地址錯了。可是請求地址沒錯。返回是一串json資料。然後我就迷糊了,後來 我發現這個url中參數是直接寫上去的

,然後parameters 放參數的地方 沒放。後來我把參數單獨寫了進來。就搞定了啊。


[appDelegate.manager GET:@"http://api.map.baidu.com/telematics/v3/weather?location=南京&output=json&ak=4zG5R7SqnQa" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {            NSDictionary *rootDict=responseObject;            NSLog(@"%@",rootDict);            NSArray *resultArray = [rootDict objectForKey:@"results"];            NSDictionary *cityDict=[resultArray objectAtIndex:0];                        //擷取城市            NSString *currentCity= [cityDict objectForKey:@"currentCity"];            //準備擷取天氣            NSArray *weatherArray= [cityDict objectForKey:@"weather_data"];            //擷取第一天天氣的字典            NSDictionary *firstDict=[weatherArray objectAtIndex:0];            //擷取第一天日期            NSString *firstDate=[firstDict objectForKey:@"date"];            //擷取第一天天氣            NSString *weather=[firstDict objectForKey:@"weather"];            //擷取第一天風向            NSString  *wind=[firstDict objectForKey:@"wind"];            //擷取第一天氣溫            NSString *temper=[firstDict objectForKey:@"temperature"];                        [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"當前城市%@\n日期:%@\n天氣%@\n風向%@\n氣溫%@\n",currentCity,firstDate,weather,wind,temper] message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil] show];        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {            NSLog(@"連結失敗");        }];    });

正確代碼:

 NSDictionary *[email protected]{@"location": @"南京",@"output": @"json",@"ak": @"4zG5R7Lw8Fd3SqnQa"};        [appDelegate.manager GET:@"http://api.map.baidu.com/telematics/v3/weather" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {

這裡的參數一定要寫再 parameters 中,不然連結裡的那些&符號。好像不識別把!



IOS 'NSInternalInconsistencyException'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.