我在使用 Sudzc(ARC 分支)解析肥皂响应时遇到问题。我有一些 WCF 服务为我们的应用程序存储数据。我设法连接到网络服务,我可以成功获得响应,但是当其中一个响应带有 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 标记的接收器节点位于其他节点(上一个项目节点)中。
提前感谢您的帮助和您的时间。