JSON解析后我无法准确输出。
strURLRootView
是NSString
“ RootViewController.m”类的对象...
strURLRootView = txt_EnterURL.text;
strURLRank
也是“CheckRank_ViewController.m”类的NSString
对象...
strURLRank = strURLRootView;
-(void)viewDidLoad
{
[self startJSONParsing];
[super viewDidLoad];
}
-(void)startJSONParsing
{
responseData = [[NSMutableData data] retain];
ArrData = [NSMutableArray array];
NSString *stringWithoutSpaces = [NSString stringWithFormat:@"http://lsapi.seomoz.com/linkscape/url-metrics/%@%2fblog?AccessID=member-10fd5cb877&Expires=1365850483&Signature=m%2F7hZu1y7Sa00NGLFKHYY%2FO3TB4%3D",strURLRank];
如果我使用
@"http://lsapi.seomoz.com/linkscape/url-metrics/www.yahoo.com%2fblog?AccessID=member-10fd5cb877&Expires=1365850483&Signature=m%2F7hZu1y7Sa00NGLFKHYY%2FO3TB4%3D"
这个 URL 静态地给出准确的输出。
NSLog(@"stringWithoutSpaces is:--> %@\n\n",stringWithoutSpaces);
NSURLRequest *request1 = [NSURLRequest requestWithURL:
[NSURL URLWithString:stringWithoutSpaces]];
NSLog(@"request1 is:--> %@\n",request1);
[[NSURLConnection alloc] initWithRequest:request1 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
{
NSLog(@"Error occured at the time of parsing...");
}
(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
results = [responseString JSONValue];
lbl_RootDomain.text = [results objectForKey:@"upl"];
lbl_URL.text = [results objectForKey:@"uu"];
lbl_Title.text = [results objectForKey:@"ut"];
lbl_SubDomain.text = [NSString stringWithFormat:@"%f",[[results objectForKey:@"fmrp"] floatValue]];
lbl_MozRank.text = [NSString stringWithFormat:@"%f",[[results objectForKey:@"umrp"] floatValue]];
lbl_DomainAutho.text = [NSString stringWithFormat:@"%d",[[results objectForKey:@"pda"] intValue]];
lbl_XternalLinks.text = [NSString stringWithFormat:@"%d",[[results objectForKey:@"ueid"] intValue]];
lbl_Links.text = [NSString stringWithFormat:@"%d",[[results objectForKey:@"uid"] intValue]];
lbl_PageAutho.text = [NSString stringWithFormat:@"%f",[[results objectForKey:@"upa"] floatValue]];
NSLog(@"results data is:--> %@",results);
NSString *str = [NSString stringWithFormat:@"Root Domain: %@\n URL: %@\n Title: %@\n Subdomain mozRank: %@\n MozRank: %@\n Domain Authority: %@\n External Links: %@\n Links: %@\n Page Authority: %@\n",lbl_RootDomain.text,lbl_URL.text,lbl_Title.text,lbl_SubDomain.text,lbl_MozRank.text,lbl_DomainAutho.text,lbl_XternalLinks.text,lbl_Links.text,lbl_PageAutho.text];
NSLog(@"mail data is:--> \n\n %@",str);
}
我在编码中没有得到确切的问题。如果我在编码方面错了,请告诉我出了什么问题。
提前致谢。