Je dois analyser les informations d'en-tête de réponse et gérer le code de statut. J'ai obtenu la chaîne de réponse html maintenant j'ai besoin de faire l'analyse comment faire dans l'iPhone?Parse Html réponse en-têtes iPhone
1
A
Répondre
0
Rechercher les éléments suivants dans la documentation:
NSString componentsSeparatedByString:
NSString componentsSeparatedByCharactersInSet:
NSScanner
classe
0
Si vous utilisez NSURLConnection
pour HTTP vous appelle pouvez obtenir le code de réponse HTTP et en-têtes des méthodes NSURLConnectionDelegate
comme suit:
- (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
sauver la réponse suivante en tant que fichier 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"]);
}
Questions connexes
- 1. JSON Array & Parse Réponse
- 2. Parse HTML Offline
- 3. réponse Parse KSoap2 dans Android
- 4. Analyse de la réponse HTML - Application iPhone
- 5. Parse Document HTML?
- 6. Parse html belle soupe
- 7. php - parse html page
- 8. PHP Parse code HTML
- 9. Excel 2008 Cant Parse HTML
- 10. Parse Server.XMLHTTP réponse YouTube avec ASP Classic
- 11. Parse Réponse XML de l'API, Javascript, Ajax
- 12. parse html chaîne avec jquery
- 13. C# parse html using XPathDocument
- 14. parse onclick liens en html
- 15. parse html dans l'air d'adobe
- 16. gtm-http-fetcher modifier entêtes HTTP
- 17. parse http en-tête de réponse de wget
- 18. jQuery: Parse/HTML sans Manipulez scripts d'exécution
- 19. Formulaire html en réponse XML et réponse
- 20. jQuery réponse html
- 21. HTML: Demande - Réponse Redirection
- 22. flash caroussel xml Parse lien html
- 23. Parse complète page html avec jquery
- 24. Parse un Résultat Valeur en HTML
- 25. Parse html avec ajax JSON dans
- 26. parse html code pour trouver un champ
- 27. Parse HTML doc avec HtmlAgilityPack-Xpath, RegExp
- 28. Parse HTML "style" attribut en utilisant Java
- 29. parse chaîne html partielle avec jquery
- 30. TouchXML Parse réponse avec les touches non cotées
de réponse HTML ou HTTP repsonse? – kennytm