我在一些iPhone应用程序中工作,它显示了来自应用程序商店的许多应用程序,我想使用json获取他们的信息。
我能够为单个应用程序执行此操作,但现在我正在尝试获取我在IBM NSMutableArray中存储其在JSon URL中使用的标识符的所有应用程序的信息。
问题是我只获取了数组中第一项的信息,而其他人则收到此错误:
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x68964a0 {NSLocalizedDescription=Unexpected end of string}"
我正在使用这些方法使用json从应用商店获取信息:
-(void)loadDatawithCode:(NSString*)_code
{
self.responseData = [NSMutableData data];
NSString * url = [NSString stringWithFormat:@"%@%@",@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?id=",_code];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
self.responseData = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
NSArray* results = [(NSDictionary*)[responseString JSONValue] objectForKey:@"results"];
[responseString release];
tmpApp= [[App alloc]init];
// assuming you have 1 valid entry
NSDictionary *result = [results objectAtIndex:0];
tmpApp.price = [result objectForKey:@"price"];
tmpApp.name=[result objectForKey:@"trackCensoredName"];
tmpApp.icon=[result objectForKey:@"artworkUrl60"];
NSLog(@"application : %@ , Price : %@ , icon path : %@",tmpApp.name, tmpApp.price,tmpApp.icon);
}
有人可能有想法吗?感谢。