5
我加載JSON與afnetworking 2.0:AFHTTPRequestOperationManager urlstring編碼和無效的參數並不令人滿意:URLString
NSString *weatherUrl = @"http://www.souche.com/pages/dicAction/loadRootLevel.json?request_message={\"type\":\"car-subdivision\"}";
weatherUrl = [weatherUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:weatherUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
控制檯錯誤:
'Invalid parameter not satisfying: URLString'
有需要的URL編碼?
,但我不喜歡這樣寫道:
NSString *weatherUrl = @"http://www.souche.com/pages/dicAction/loadRootLevel.json?request_message={%22type%22:%22car-subdivision%22}";
仍然錯誤!
我該怎麼辦?
將在你的URL字符串以.json。其他的東西,參數,應該放在一個NSDictionary中,並傳遞給'parameters'(你現在傳遞'nil'。) –
@AaronBrager謝謝,它可以與NSDictionary一起工作。 – justin