我需要解析响应头信息并处理状态码。我现在得到了html响应字符串,我需要解析如何在iPhone中完成操作?解析Html响应头iPhone
1
A
回答
0
查找文档中的以下内容:
NSString componentsSeparatedByString:
NSString componentsSeparatedByCharactersInSet:
NSScanner
类
0
如果使用NSURLConnection
用于HTTP调用就可以得到HTTP响应代码和来自NSURLConnectionDelegate
方法的标题如下:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSInteger statusCode = [httpResponse statusCode];
NSDictionary* headers = [httpResponse allHeaderFields];
}
0
NSMutableDictionary *n=[[NSMutableDictionary alloc]init];
NSString *[email protected]"asd";
NSString *s=[[[[str componentsSeparatedByString:@"<"] objectAtIndex:1] componentsSeparatedByString:@">"]objectAtIndex:0];
NSArray *a = [s componentsSeparatedByString:@"|"];
[n setObject:[a objectAtIndex:0] forKey:@"status"];
if([a count]>1)
{
[n setObject:[a objectAtIndex:1] forKey:@"session"];
NSArray *b = [[a objectAtIndex:2] componentsSeparatedByString:@"&"];
for(int i=0;i<[b count];i++)
{
NSArray *arr = [[b objectAtIndex:i ] componentsSeparatedByCharactersInSet:[ NSCharacterSet characterSetWithCharactersInString:@",="]];
NSMutableIndexSet *eset=[[NSMutableIndexSet alloc]init];
NSMutableIndexSet *oset=[[NSMutableIndexSet alloc]init];
for(int j=0;j<[arr count];j=j+2)
{
[eset addIndex:j];
[oset addIndex:j+1];
}
NSArray *names = [arr objectsAtIndexes: eset];
NSArray *values = [arr objectsAtIndexes: oset];
NSDictionary * dict = [NSDictionary dictionaryWithObjects:values forKeys:names];
[n setObject:dict forKey:[dict objectForKey:@"DisplayName"]];
}
NSLog(@"%@",n);
}
0
节省以下响应作为sample.json文件
{
"Category": [
{
"name": "Mobile"
},
{
"name": "TV"
},
{
"name": "Computer"
},
{
"name": "Camera"
},
{
"name": "Home Appilances"
}
]
}
NSError *error = nil;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:myData options:kNilOptions error:&error];
NSArray *catArray = [dict objectForKey:@"Category"];
for (int index = 0; index < catArray.count; index++) {
NSDictionary *valDic = [catArray objectAtIndex:index];
NSLog(@"%@", [valDic objectForKey:@"name"]);
}
相关问题
- 1. 解析HTML响应 - iPhone App
- 2. 如何使用Ruby解析不带响应头的HTML响应
- 3. 解析响应和响应头PHP
- 4. 解析HTML获取响应
- 5. HTML解析器响应 - Java
- 6. 解析HTML iPhone
- 7. 如何解析PHP中的响应头?
- 8. Python解析DNS响应标头
- 9. django解析响应头X-Auth
- 10. HttpWebResponse.GetResponse()fiddler说:“响应头解析失败。”
- 11. 从wget解析http响应标头
- 12. 如何在iphone中解析json响应?
- 13. 解析JSON响应iphone目标C
- 14. 使用ASIHTTPRequest为iPhone解析响应
- 15. 解析肥皂响应问题(iphone/touchxml)
- 16. iPhone:解析响应字典问题:
- 17. 解析响应
- 18. 解析响应
- 19. 如何解析此html响应?
- 20. 在jQuery中解析HTML响应
- 21. iPhone SDK:hpple HTML解析器SIGABRT
- 22. html解析iPhone的SDK?
- 23. iPhone,使用TouchXML解析HTML
- 24. HTML在iphone解析sdk
- 25. XML响应解析
- 26. 解析json响应
- 27. 解析XML响应
- 28. 解析Json响应
- 29. 解析JSON响应
- 30. 解析HTTParty响应
HTML响应或HTTP repsonse? – kennytm 2010-01-20 07:11:24