在下面的代碼JSONparsing方法工作正常,但是當我更改odataJsonParsing方法中的url時:http://192.168.1.37:8000/sap/opu/odata/sap/ZGW_BANK_DATA_SRV/BankSet? $ filter =(BankCtry%20eq%20%27IN%27)& $ format = json無法加載數據,它顯示爲零,但同樣的方法正常工作的剩餘網址,任何人都可以告訴我我錯了什麼地方。使用NSURL授權的JSON解析
**Condition**: In odataJsonParsing method have authorization credentials like.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@"http://192.168.1.37:8000/sap/opu/odata/sap/ZGW_BANK_DATA_ SRV/BankSet?$filter=(BankCtry%20eq%20%27US%27)&$format=json"]];
[request setHTTPMethod: @"GET" ];
// [request setHTTPBody:self.requestData];
[request setValue:@"XXXXXXX" forHTTPHeaderField:@"username"];
[request setValue:@"XXXXXXX" forHTTPHeaderField:@"password"];
[request setValue:[[NSUserDefaults standardUserDefaults]valueForKey:@"Auth"] forHTTPHeaderField:@"Authorization"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
-----------------------------------------------------------------
-(void)JSONParsing
{
NSError *error;
//--------------------------URLS----------------------------//
//http://api.geonames.org/citiesJSON? north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo
//http://api.kivaws.org/v1/loans/search.json?status=fundraising
//http://192.168.1.37:8000/sap/opu/odata/sap/ZGW_BANK_DATA_SRV/BankSet? $filter=(BankCtry%20eq%20%27IN%27)&$format=json
//http://jsonplaceholder.typicode.com/posts
NSURL *url=[NSURL URLWithString:@"http://jsonplaceholder.typicode.com/posts"];
NSData *jsonData=[[NSData alloc] initWithContentsOfURL:url];
if(jsonData!=nil){
NSDictionary *jsonArray=[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
NSLog(@"%@",jsonArray);
}
}
-(void)oDataJsonParsing
{
NSError *error;
NSData *jsonData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.37:8000/sap/opu/odata/sap/ZGW_BANK_DATA_ SRV/BankSet?$filter=(BankCtry%20eq%20%27IN%27)&$format=json"]];
NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
NSLog(@"%@",dic);
}
你想說什麼呢? –