求助:Three20 使用TTURLXMLResponse 获取XML问题
在写一个
xml读取数据的程序。
使用了 TTURLXMLResponse 这个 Three20 扩展。
根据网上找出的各种源码,已能成功读取远端的XML内容,但获取的内容 是一个 NSDictionary 对象,内容完全不象XML返回的内容
也许 NSDictionary 可以处理与读取,但我不会,向大家求助。
XML源码:
很普通的XML
获取部分的源码
打印出来 feed 的内容,应该是正确获取了,但如何处理,不清楚该怎么做
根据网上找出的各种源码,已能成功读取远端的XML内容,但获取的内容 是一个 NSDictionary 对象,内容完全不象XML返回的内容
也许 NSDictionary 可以处理与读取,但我不会,向大家求助。
XML源码:
复制代码
|
很普通的XML
获取部分的源码
复制代码
|
打印出来 feed 的内容,应该是正确获取了,但如何处理,不清楚该怎么做
复制代码
|
自己研究。终于解决。源码奉上
//读取进程
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
if (!self.isLoading && TTIsStringWithAnyText(_searchQuery)) {
NSString* url = @"http://192.168.1.2/iphone/magazine.xml";
TTURLRequest* request = [TTURLRequest
requestWithURL: url
delegate: self];
request.cachePolicy = cachePolicy;
request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER;
TTURLXMLResponse* response = [[TTURLXMLResponse alloc] init];
response.isRssFeed = YES;
request.response = response;
TT_RELEASE_SAFELY(response);
[request send];
}
}
- (void)requestDidFinishLoad:(TTURLRequest*)request {
TTURLXMLResponse *response = request.response;
TTDASSERT([response.rootObject isKindOfClass:[NSDictionary class]]);
NSDictionary * rootObject = response.rootObject;
TTDASSERT([[rootObject objectForKey:@"channel"] isKindOfClass:[NSDictionary class]]);
NSDictionary *channel = [rootObject objectForKey:@"channel"];
TTDASSERT([[channel objectForKey:@"item"] isKindOfClass:[NSDictionary class]]);
NSMutableArray* feeds = [[NSMutableArray alloc] init];
NSArray* entries = [channel objectForKey:@"item"];
for(int i=0;i<[entries count];i++){
NSDictionary* entry = [entries objectAtIndex:i];
Magazine* d = [[Magazine alloc] init];
NSDictionary* v2 = [entry objectForKey:@"title"];
d.subject = [v2 objectForKey:@"___Entity_Value___"];
NSDictionary* v3 = [entry objectForKey:@"description"];
d.description = [v3 objectForKey:@"___Entity_Value___"];
NSDictionary* v4 = [entry objectForKey:@"img_57"];
d.img_57 = [v4 objectForKey:@"___Entity_Value___"];
[feeds addObject:d];
}
_feeds = feeds;
[super requestDidFinishLoad:request];
}
返回的是一整套的类似JSON格式的东东,要反复打碎,解析,最后搞定。
转: http://www.cocoachina.com/bbs/read.php?tid-61730.html