我从服务器获取xml类型的响应,但是我无法通过解析来获取值,不能在哪里找不到的东西
这是来自服务器的示例响应:
<admin>
<logindetails
status="cdcdvfbgfhgfgfbff"
timestamp="1494499694240" isdaylighton="true"
isupdateavailable="false" updateurl="" user="1"
userParentID="0">Success</logindetails><admin>
我的解析方法:
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(@"Element Name :%@",elementName);
recordResults =NO;
if ([elementName isEqualToString:@"logindetails"]) {
data = [soapResultsString dataUsingEncoding:NSUTF8StringEncoding];
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"json===>%@",array);
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( recordResults )
{
[childElement appendString: string];
NSLog(@"inside%@",string);
}
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
xmlparserString=elementName;
NSLog(@"xmlparserString start -->%@",xmlparserString);
if( [xmlparserString isEqualToString:@"logindetails"])
{
recordResults =YES;
soapResultsString = [[NSMutableString alloc] init];
}
}
iam获取所有标签名称,但我无法从Xml响应中获取值,请检查代码并回答
答案 0 :(得分:2)
您要查找的数据是 XML属性,并在attributes
的{{1}}词典中返回。
didStartElement
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *) elementName
namespaceURI:(NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict
{
xmlparserString = elementName;
NSLog(@"xmlparserString start -->%@",xmlparserString);
if ([xmlparserString isEqualToString:@"logindetails"]) {
// soapResultsString = [[NSMutableString alloc] init];
NSLog(@"logindetails attributes --> %@", attributeDict);
}
中的JSON反序列化是错误的,无法正常工作。 XML属性不是JSON。删除整个didEndElement
表达式