开发者

Newbie IPhone Removing Soap Envelope

I am looking for a way to remove the envelope around my SOAP Response. The Data is in JSON but doesnt really have level开发者_StackOverflow中文版s so if I can remove the envelope I know I can parse it because I put the data into a json file and got the parser working for it. My only problem when I get the response from the server is the envelope surrounding the data.

I have looked alot but cant seem to find a answer. Any help and sample code is appreciated!

This is my soap response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <AuthenticateUserResponse xmlns="http://tempuri.org/">
         <AuthenticateUserResult>{"isValid":true,"isContractor":false,"isExpired":false,"isApproved":true,"userID":"e2be94cb-2e74-4eae-91a9-d874735b8647","userType":"DUMP ","trucks":1}</AuthenticateUserResult>
      </AuthenticateUserResponse>
   </s:Body>
</s:Envelope>

I am looking to pull this.

{"isValid":true,"isContractor":false,"isExpired":false,"isApproved":true,"userID":"e2be94cb-2e74-4eae-91a9-d874735b8647","userType":"DUMP ","trucks":1}

I could be taking a wrong approach but any help is greatly appreciated.


This may or may not be overkill for your needs, but here's how I'm doing it.

Get yourself an NSXMLParser. Set its delegate.

In the delegate, look for these methods:

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

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)characters

In the didStartElement method, check if elementName is AuthenticateUserResult. If it is, set a boolean isInAuthenticateUserResult = YES;

In the didEndElement method, set that boolean to no.

In the foundCharacters method, if the boolean is YES then the characters are your JSON.


Considering the envelope is just XML have you looked at using NSXMLParser to just parse the XML and get the value you want? If you don't like writing stream parsers, you could also check out something like TouchXML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜