0

xcode 4から.netで記述されたWebサービスを呼び出しています。出力はjson文字列です。静的IPアドレスを使用してURLで呼び出しを行うと、エラーが発生します。HTTPエラー404.0-見つかりません。ただし、ローカルホストで同じURLが呼び出された場合は機能します。コードを以下に示します

- (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;
} 
4

1 に答える 1

1
ithink the error was here try now:


NSURL *url=[NSURL URLWithString:@"your address"];/<------ here was the error
    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;
于 2013-03-27T12:06:00.403 に答える