2010-04-28 3 views
0

Google 날씨 API를 사용하는 xcode의 iphone 응용 프로그램과 함께 작업하고 있습니다. 내가 API에 연결할 때하지만 그때의 내가이 데이터를 읽는 방법을 알아낼 수 없습니다이iPhone 날씨 예보 응용 프로그램

- (void)viewDidLoad 
{ 
    NSString *[email protected]"Kolkata"; 
    NSString *URLString = [NSString stringWithFormat:@"http://www.google.com/ig/api?weather=%@", currentLocation]; 
    NSLog(@"urlstring: %@", URLString); 

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    if (theConnection) 
    { 

     responseData = [[NSMutableData alloc] retain]; 
    } 


    [super viewDidLoad]; 

} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [responseData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    NSLog(@"Receiving data..."); 
    [responseData appendData:data]; 
    NSLog(@"responsedata: %@",responseData); 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"Reverse Geocode request to Google failed!"); 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"Finished loading..."); 
    [connection release]; 

} 

처럼 나에게

2010-04-28 12:19:56.903 weather[176:20b] urlstring: http://www.google.com/ig/api?weather=Kolkata 
2010-04-28 12:19:57.214 weather[176:20b] Receiving data... 2010-04-28 12:19:57.215 weather[176:20b] responsedata: <3c3f786d 6c207665 7273696f 6e3d2231 2e30223f 3e3c786d 6c5f6170 695f7265 706c7920 76657273 696f6e3d 2231223e 3c776561 74686572 206d6f64 756c655f 69643d22 30222074 61625f69 643d2230 22206d6f 62696c65 5f726f77 3d223022 206d6f62 696c655f 7a697070 65643d22 31222072 6f773d22 30222073 65637469 6f6e3d22 3022203e 3c666f72 65636173 745f696e 666f726d 6174696f 6e3e3c63 69747920 64617461 3d224b6f 6c6b6174 612c2057 65737420 42656e67 616c222f 3e3c706f 7374616c 5f636f64 65206461 74613d22 4b6f6c6b 61746122 2f3e3c6c 61746974 7564655f 65362064 6174613d 22222f3e 3c6c6f6e 67697475 64655f65 36206461 74613d22 222f3e3c 666f7265 63617374 5f646174 65206461 74613d22 32303130 2d30342d 3238222f 3e3c6375 7272656e 745f6461 74655f74 696d6520 64617461 3d223230 31302d30 342d3238 2030363a 32303a30 30202b30 30303022 2f3e3c75 6e69745f 73797374 656d2064 6174613d 22555322 2f3e3c2f 666f7265 63617374 5f696e66 6f726d61 74696f6e 3e3c6375 7272656e 745f636f 6e646974 696f6e73 3e3c636f 6e646974 696f6e20 64617461 3d224861 7a65222f 3e3c7465 6d705f66 20646174 613d2239 37222f3e 3c74656d 705f6320 64617461 3d223336 222f3e3c 68756d69 64697479 20646174 613d2248 756d6964 6974793a 20363025 222f3e3c 69636f6e 20646174 613d222f 69672f69 6d616765 732f7765 61746865 722f6861 7a652e67 6966222f 3e3c7769 6e645f63 6f6e6469 74696f6e 20646174 613d2257 696e643a 20532061 74203133 206d7068 222f3e3c 2f637572 72656e74 5f636f6e 64697469 6f6e733e 3c666f72 65636173 745f636f 6e646974 696f6e73 3e3c6461 795f6f66 5f776565 6b206461 74613d22 57656422 2f3e3c6c 6f772064 6174613d 22383222 2f3e3c68 69676820 64617461 3d223931 222f3e3c 69636f6e 20646174 613d222f 69672f69 6d616765 732f7765 61746865 722f6368 616e6365 5f6f665f 7261696e 2e676966 222f3e3c 636f6e64 6974696f 6e206461 74613d22 4368616e 6365206f 66205261 696e222f 3e3c2f66 6f726563 6173745f 636f6e64 6974696f 6e733e3c 666f7265 63617374 5f636f6e 64697469 6f6e733e 3c646179 5f6f665f 7765656b 20646174 613d2254 6875222f 3e3c6c6f 77206461 74613d22 3832222f 3e3c6869 67682064 6174613d 22393622 2f3e3c69 636f6e20 64617461 3d222f69 672f696d 61676573 2f776561 74686572 2f726169 6e2e6769 66222f3e 3c636f6e 64697469 6f6e2064 6174613d 22526169 6e222f3e 3c2f666f 72656361 73745f63 6f6e6469 74696f6e 733e3c66 6f726563 6173745f 636f6e64 6974696f 6e733e3c 6461795f 6f665f77 65656b20 64617461 3d224672 69222f3e 3c6c6f77 20646174 613d2238 32222f3e 3c686967 68206461 74613d22 3936222f 3e3c6963 6f6e2064 6174613d 222f6967 2f696d61 6765732f 77656174 6865722f 73756e6e 792e6769 66222f3e 3c636f6e 64697469 6f6e2064 6174613d 22436c65 6172222f 3e3c2f66 6f726563> 2010-04-28 12:19:57.217 weather[176:20b] Receiving data... 2010-04-28 12:19:57.217 weather[176:20b] responsedata: <3c3f786d 6c207665 7273696f 6e3d2231 2e30223f 3e3c786d 6c5f6170 695f7265 706c7920 76657273 696f6e3d 2231223e 3c776561 74686572 206d6f64 756c655f 69643d22 30222074 61625f69 643d2230 22206d6f 62696c65 5f726f77 3d223022 206d6f62 696c655f 7a697070 65643d22 31222072 6f773d22 30222073 65637469 6f6e3d22 3022203e 3c666f72 65636173 745f696e 666f726d 6174696f 6e3e3c63 69747920 64617461 3d224b6f 6c6b6174 612c2057 65737420 42656e67 616c222f 3e3c706f 7374616c 5f636f64 65206461 74613d22 4b6f6c6b 61746122 2f3e3c6c 61746974 7564655f 65362064 6174613d 22222f3e 3c6c6f6e 67697475 64655f65 36206461 74613d22 222f3e3c 666f7265 63617374 5f646174 65206461 74613d22 32303130 2d30342d 3238222f 3e3c6375 7272656e 745f6461 74655f74 696d6520 64617461 3d223230 31302d30 342d3238 2030363a 32303a30 30202b30 30303022 2f3e3c75 6e69745f 73797374 656d2064 6174613d 22555322 2f3e3c2f 666f7265 63617374 5f696e66 6f726d61 74696f6e 3e3c6375 7272656e 745f636f 6e646974 696f6e73 3e3c636f 6e646974 696f6e20 64617461 3d224861 7a65222f 3e3c7465 6d705f66 20646174 613d2239 37222f3e 3c74656d 705f6320 64617461 3d223336 222f3e3c 68756d69 64697479 20646174 613d2248 756d6964 6974793a 20363025 222f3e3c 69636f6e 20646174 613d222f 69672f69 6d616765 732f7765 61746865 722f6861 7a652e67 6966222f 3e3c7769 6e645f63 6f6e6469 74696f6e 20646174 613d2257 696e643a 20532061 74203133 206d7068 222f3e3c 2f637572 72656e74 5f636f6e 64697469 6f6e733e 3c666f72 65636173 745f636f 6e646974 696f6e73 3e3c6461 795f6f66 5f776565 6b206461 74613d22 57656422 2f3e3c6c 6f772064 6174613d 22383222 2f3e3c68 69676820 64617461 3d223931 222f3e3c 69636f6e 20646174 613d222f 69672f69 6d616765 732f7765 61746865 722f6368 616e6365 5f6f665f 7261696e 2e676966 222f3e3c 636f6e64 6974696f 6e206461 74613d22 4368616e 6365206f 66205261 696e222f 3e3c2f66 6f726563 6173745f 636f6e64 6974696f 6e733e3c 666f7265 63617374 5f636f6e 64697469 6f6e733e 3c646179 5f6f665f 7765656b 20646174 613d2254 6875222f 3e3c6c6f 77206461 74613d22 3832222f 3e3c6869 67682064 6174613d 22393622 2f3e3c69 636f6e20 64617461 3d222f69 672f696d 61676573 2f776561 74686572 2f726169 6e2e6769 66222f3e 3c636f6e 64697469 6f6e2064 6174613d 22526169 6e222f3e 3c2f666f 72656361 73745f63 6f6e6469 74696f6e 733e3c66 6f726563 6173745f 636f6e64 6974696f 6e733e3c 6461795f 6f665f77 65656b20 64617461 3d224672 69222f3e 3c6c6f77 20646174 613d2238 32222f3e 3c686967 68206461 74613d22 3936222f 3e3c6963 6f6e2064 6174613d 222f6967 2f696d61 6765732f 77656174 6865722f 73756e6e 792e6769 66222f3e 3c636f6e 64697469 6f6e2064 6174613d 22436c65 6172222f 3e3c2f66 6f726563 6173745f 636f6e64 6974696f 6e733e3c 666f7265 63617374 5f636f6e 64697469 6f6e733e 3c646179 5f6f665f 7765656b 20646174 613d2253 6174222f 3e3c6c6f 77206461 74613d22 3738222f 3e3c6869 67682064 6174613d 22393822 2f3e3c69 636f6e20 64617461 3d222f69 672f696d 61676573 2f776561 74686572 2f6d6f73 746c795f 73756e6e 792e6769 66222f3e 3c636f6e 64697469 6f6e2064 6174613d 224d6f73 746c7920 53756e6e 79222f3e 3c2f666f 72656361 73745f63 6f6e6469 74696f6e 733e3c2f 77656174 6865723e 3c2f786d 6c5f6170 695f7265 706c793e> 2010-04-28 12:19:57.219 weather[176:20b] Finished loading... 

내 코드가 보이는 다음과 같은 출력을 제공합니다.

당신의 귀중한 도움을 찾고 있습니다. 나는 당신이있는 NSData을 사용하고 있기 때문에 이것이 의심 사전

+0

어쩌면 일부 작업 코드를 게시하여 작업 내용을 더 잘 이해할 수 있습니다. – schaechtele

답변

0

이 URL (http://www.google.com/ig/api?weather=kolkata)

감사를 사용하고 있습니다. NSString으로 변환 해 보거나 stringWithContentsOfURL과 같은 메서드를 반환하는 NSString을 사용하십시오. 인코딩 : 오류 :

+0

감사합니다 ustun, 저를 위해 절대적으로 잘 작동했습니다. 고마워 .. 안녕히 계십시오. – Joy