0
我打電話給web服務從xcode 4編寫.net輸出是一個json字符串.when該調用與URL使用靜態ip地址它給出error.HTTP錯誤404.0 - 未找到。但工作時相同的URL被稱爲localhost.the代碼如下從xcode獲取json
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url=[NSURLURLWithString:@"http:// static ip address where serviceis located(169.254.216.8)/restGroceryService/WebService/insertList?prods=apples,bananas,milk"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *pageSource = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"page source%@",pageSource);
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSArray *array = [json objectForKey:@"result"];
NSDictionary *store = [array objectAtIndex:0];
NSNumber *storeId = [store objectForKey:@"storeId"];
NSNumber *total = [store objectForKey:@"TOTAL"];
self.priceTextField.text =[total stringValue];
NSString *storeName = [store objectForKey:@"storeName"];
self.storNameTextField.text = storeName;
}
爲什麼有這麼多的新行被賦予?你喜歡滾動嗎? – 2012-07-10 19:41:46
我認爲您使用的是本地IP,並且您嘗試使用3G網絡訪問它。它不會工作。您必須連接到本地wifi或使用外部IP地址。 – George 2012-07-10 20:59:26