我使用Sudzc(ARC分支)解析soap响应时遇到问题。我有一些WCF服务存储我们的应用程序的数据。我设法连接到Web服务我可以成功获得响应,但是当其中一个响应带有z:ref属性时我卡住了。没有一个例子很难解释对吗? ;)/我用例如“#someid”替换了重要数据,所以不要指出它是一个问题;)
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId>#some credentials </ActivityId>
</s:Header>
<s:Body>
<GetMessagesResponse >
<GetMessagesResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AllItemsCount>2</AllItemsCount>
<Items>
<Message z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<GlobalId>#msgid</GlobalId>
<Content>bbbbbbbb</Content>
<CreatedDate>2013-02-14T16:33:07</CreatedDate>
<Priority>Normal</Priority>
<Receiver z:Id="i2">
<GlobalId>#receiverid</GlobalId>
<CountryId>37</CountryId>
<CreationDate>2013-01-31T16:12:40</CreationDate>
<Gender>Male</Gender>
<IsDeleted>false</IsDeleted>
<Picture i:nil="true" />
<UserName>tobiasz</UserName>
</Receiver>
<Sender z:Id="i3">
<GlobalId>#senderid</GlobalId>
<CountryId>6</CountryId>
<CreationDate>2013-02-04T13:08:40</CreationDate>
<Gender>Male</Gender>
<IsDeleted>false</IsDeleted>
<Picture >
#"picture info"
</Picture>
<UserName>tobiasz2</UserName>
</Sender>
<Topic>RE: 56765765</Topic>
</Message>
<Message z:Id="i4" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<GlobalId>#msgid2</GlobalId>
<Content>aaaaaaa</Content>
<CreatedDate>2013-02-14T16:31:01</CreatedDate>
<Priority>High</Priority>
<Receiver z:Ref="i2"/>
<Sender z:Ref="i3"/>
<Topic>RE: 56765765</Topic>
</Message>
</Items>
<PageIndex>0</PageIndex>
<RetrievedDateTime>2013-02-15T13:14:57.0813487Z</RetrievedDateTime>
</GetMessagesResult>
</GetMessagesResponse>
</s:Body>
如您所见,有些线路将Receiver节点标识为i2 您还可以看到来自同一发件人和同一接收者的另一条消息的节点
sudzc生成的用于解析此xml的类:
@interface ResultOfGetMessages : SoapObject{
int _AllItemsCount;
NSMutableArray* _Items;
int _PageIndex;
NSDate* _RetrievedDateTime;
}
@interface Message : WSGlobalObject{
NSString* _Content;
NSDate* _CreatedDate;
NSString* _Priority;
User* _Receiver;
User* _Sender;
NSString* _Topic;
}
@interface User : WSGlobalObject{
int _CountryId;
NSDate* _CreationDate;
NSString* _Gender;
BOOL _IsDeleted;
PictureInfo* _Picture;
NSString* _UserName;
}
使用Touchxml的Sudz无法读取(获取null接收者和发送者),响应被解析为:
<ResultOfGetMessages>
<AllItemsCount>2</AllItemsCount>
<Items>
<Message>
<GlobalId>###</GlobalId>
<Content>bbbbbbbb</Content>
<CreatedDate>2013-02-14T16:33:07.000</CreatedDate>
<Priority>Normal</Priority>
<Receiver>
<GlobalId>####</GlobalId>
<CountryId>37</CountryId>
<CreationDate>2013-01-31T16:12:40.000</CreationDate>
<Gender>Male</Gender>
<IsDeleted>false</IsDeleted>
<Picture i:nil="true" ></Picture>
<UserName>tobiasz</UserName>
<Version>11</Version>
</Receiver>
<Sender>
<GlobalId>e4bda93c-a11c-4ae2-baf1-a15b00e918e7</GlobalId>
<CountryId>6</CountryId>
<CreationDate>2013-02-04T13:08:40.000</CreationDate>
<Gender>Male</Gender>
<IsDeleted>false</IsDeleted>
<Picture >
####
</Picture>
<UserName>tobiasz2</UserName>
<Version>11</Version>
</Sender>
<Topic>RE: 56765765</Topic>
</Message>
<Message>
<GlobalId>###</GlobalId>
<Content>aaaaaaa</Content>
<CreatedDate>2013-02-14T16:31:01.000</CreatedDate>
<Priority>High</Priority>
<Receiver>
<CountryId>0</CountryId>
<IsDeleted>false</IsDeleted>
</Receiver>
<Sender>
<CountryId>0</CountryId>
<IsDeleted>false</IsDeleted>
</Sender>
<Topic>RE: 56765765</Topic>
</Message>
</Items>
<PageIndex>0</PageIndex>
我认为问题在于反序列化的深度。解析器(if)尝试获取具有指定id的接收器节点但是它失败,因为标记有此id的接收器节点位于其他节点(前一个项目节点)中。
提前感谢您的帮助和时间。
答案 0 :(得分:0)
在序列化节点时,soap.m遇到了类似的问题。不得不这个代码:
// Deserializes the element in a dictionary.
+(id)deserializeAsDictionary:(CXMLNode*)element {
if([element childCount] == 1) {
CXMLNode* child = [[element children] objectAtIndex:0];
if([child kind] == CXMLTextKind)
{
NSLog(@"The Child Node: %@", [[[element children] objectAtIndex:0] stringValue]);
return [[[element children] objectAtIndex:0] stringValue];
}
}
NSMutableDictionary* d = [NSMutableDictionary dictionary];
for(CXMLNode* child in [element children]) {
id v = [Soap deserialize:child];
if(v == nil) { v = [NSNull null]; }
[d setObject:v forKey:[child name]];
}
return d;
}
为:
// Deserializes the element in a dictionary.
+(id)deserializeAsDictionary:(CXMLNode*)element {
if([element childCount] == 1) {
CXMLNode* child = [[element children] objectAtIndex:0];
if([child kind] == CXMLTextKind)
{
NSLog(@"The Child Node: %@", [[[element children] objectAtIndex:0] stringValue]);
return [[[element children] objectAtIndex:0] stringValue];
}
}
NSMutableDictionary* d = [NSMutableDictionary dictionary];
for(CXMLNode* child in [element children]) {
id v = [Soap deserialize:child];
if(v == nil) { v = [NSNull null]; }
[d setObject:v forKey:[child name]];
if( check != nil ) {
NSInteger next = 1;
key = [NSString stringWithFormat:@"%@%04d", [child name], next];
check = [d objectForKey:key];
while( check != nil ) {
next++;
key = [NSString stringWithFormat:@"%@%04d", [child name], next];
check = [d objectForKey:key];
}
[d setObject:v forKey:key];
} else {
[d setObject:v forKey:[child name]];
}