이 잘 나는 XML을 다른 사람보다 몇 가지 다른 방법을 분석하고 내가 정말 어떤 기술 모른다 솔직하게하지만 난 당신이 나를 위해 잘 작동 보장과 나는 많은 프로젝트에 성공적으로 implemeted했다. 좀 profile
이에서 트윗을로드 할 경우 내 코드에서보세요 것은 내가 파서 전화를 걸 수있는 기능입니다.
-(void)loadtweet
{
@try
{
NSString *urlString = [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=SrBachchan&count=5"];
NSLog(@"fetching data from--------> : %@",urlString);
NSString* escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:escapedUrlString]];
NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:request1 delegate:self];
if(con)
truckData=[[NSMutableData data]retain];
}
@catch (NSException *exception)
{
UIAlertView *v = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Please Try Again Later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[v show];
[v release];
}
}
그리고 이것들은 NSURLConnection
위임 방법은 다음과 같습니다
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[truckData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[truckData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[tweets removeAllObjects];
@try
{
// [app.trucks removeAllObjects];
NSString *thexml=[[NSString alloc] initWithBytes:[truckData mutableBytes] length:[truckData length] encoding:NSUTF8StringEncoding];
NSArray *array=[thexml componentsSeparatedByString:@"<status>"];
NSLog(@"%d",[array count]);
for(int i=1;i<[array count];i++)
{
NSString *str=[array objectAtIndex:i];
NSArray *arr1=[str componentsSeparatedByString:@"<text>"];
NSString *data=[arr1 objectAtIndex:1];
NSRange ranfrom=[data rangeOfString:@"</text>"];
// nt.truckName=[data substringToIndex:ranfrom.location];
[tweets addObject:[data substringToIndex:ranfrom.location]];
}
}
@catch (NSException *exception)
{
UIAlertView *v = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Please Try Again Later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[v show];
[v release];
}
}
내가 태그를 분리하기 위해 몇 가지 문자열 함수를 사용하고 배열의 값을 저장했다. [당신이 시도 무엇?]
(http://whathaveyoutried.com)는 XML을 구문 분석 애플의 API가 [잘 문서화 (https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual /XMLParsing/XMLParsing.html) 및 예시 [샘플 코드]를 갖는다 (https://developer.apple.com/library/ios/samplecode/SeismicXML/). 이것들은 당신에게 당신의 문제를 어떻게 해결할 것인지 정확하게 알려주지는 않지만, 거기에서 당신의 길을 찾을 수있을만큼 API에 익숙해 지거나 더 구체적인 질문을해야합니다. – rickster
Ishu의 링크로 이동할 수도 있습니다. 내 메서드는 문자열 함수와 함께 재생하고 이해하기 쉽습니다. 당신이 쉽게 찾을 수있는 것을 채택하십시오. 그러나 당신은 구현하기 전에 그것을 잘 이해하고 있습니다. 행운을 빕니다. –