0
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><IOSAPIProjectResponse xmlns="http://tempuri.org/">
    <IOSAPIProjectResult>{"result":[{"projectcatname":"Test1","projectname":"Sample1","imgname":"http://someurl.com/UploadImages/projects/5.jpg"},{"projectcatname":"Test2","projectname":"Sample2","imgname":"http://someurl.com/UploadImages/projects/6.jpg"}],"status":"SUCCESS"}
    </IOSAPIProjectResult></IOSAPIProjectResponse></soap:Body></soap:Envelope>

我从 .asmx API 收到以下响应,如何从响应中获取结果?

4

2 回答 2

0

这是一个 XML 结果,使用 NSXMLParser,你应该使用的主要方法是:

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
[parser parse];

检查当前元素:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;

要从此元素获取字符串:

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

于 2013-10-29T19:16:04.613 回答
0

看起来您正在将响应编码为 JSON。iOS 内置了 JSON 解码功能。我建议阅读NSJSONSerialization 类参考

简而言之,您可以使用以下方式NSDictionary从 JSON 编码数据中获取对象:

NSError* error;
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:responseData 
options:kNilOptions 
error:&error];

然后使用NSDicitionary对象来获得你正在寻找的结果objectForKey

于 2013-10-29T19:32:33.143 回答