我从网络服务获取这个字符串“Rasberry & Banana Smoothies”,它把字符串作为三个不同的值而不是一个值:
覆盆子
香蕉
冰沙
如果我&
从服务器数据库中删除符号,它会按原样获取完整的字符串。
我不明白为什么会这样,有人可以指导我吗?
提前致谢。
在这里,我发布了获取它的代码,这可能有助于理解问题:
- (void)viewDidLoad
{
[super viewDidLoad];
arrayTitle = [[NSMutableArray alloc]init];
arrayImage = [[NSMutableArray alloc]init];
arrayRecipe = [[NSMutableArray alloc]init];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"2-right-side-sheet-1.png"]];
NSString *url=[[NSString alloc]initWithFormat:@"http://smoktec.net/Monty/api/?"];
NSString *Action=@"action=";
NSString *compUrl=[[NSString alloc]initWithFormat:@"%@%@%@",url,Action,@"Recipes"];
NSURL *urlToPars= [NSURL URLWithString:compUrl];
NSLog(@"%@",compUrl);
[self parseWithUrl3:urlToPars];
}
-(void)parseWithUrl3:(NSURL *)compUrl
{
parser=[[NSXMLParser alloc]initWithContentsOfURL:compUrl];
[parser setDelegate:self];
[parser parse];
[parser release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
stcurrentelement=[NSString stringWithFormat:@"%@",elementName];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(!(stcurrentelement==nil))
{
if([stcurrentelement isEqualToString:@"Recipetitle"])
{
[arrayTitle addObject:string];
NSLog(@"%@",string);
}
else if([stcurrentelement isEqualToString:@"RecipeImg"])
{
[arrayImage addObject:string];
NSLog(@"%@",string);
}
else if([stcurrentelement isEqualToString:@"Recipeid"])
{
[arrayRecipe addObject:string];
NSLog(@"%@",string);
}
}
}