Sudzc deserializeAsDictionary:over writing dictionary [英] Sudzc deserializeAsDictionary: over written dictionary
本文介绍了Sudzc deserializeAsDictionary:over writing dictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sudzc生成的代码正在为反序列化节点编写字典。如果我使用NSLog(@子节点:%@,[[[element children] objectAtIndex:0] stringValue]);它会在每次通过时写出正确的项目。当我尝试在代码中检索结果时,只有最后一个可用(杰克逊3)。我究竟做错了什么?
The Sudzc generated code is over writing a dictionary for deserialized nodes. If I use the NSLog(@"The Child Node: %@", [[[element children] objectAtIndex:0] stringValue]); it will write the correct items out each time it passed through. When I try to retrieve the results in code only the last one is available (Jackson 3). What am I doing wrong?
// 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;
}
NSLog:
2012-04-19 14:13:07.802 Management[3043:10703] Hopefully Child: Allen
2012-04-19 14:13:07.803 Management[3043:10703] Hopefully Child: 1
2012-04-19 14:13:07.804 Management[3043:10703] Hopefully Child: John
2012-04-19 14:13:07.804 Management[3043:10703] Hopefully Child: 2
2012-04-19 14:13:07.805 Management[3043:10703] Hopefully Child: Jackson
2012-04-19 14:13:07.805 Management[3043:10703] Hopefully Child: 3
XML:
<TC diffgr:id="TC1" msdata:rowOrder="0">
<CSHR_POS_NAME>Allen</CSHR_POS_NAME>
<CSHR_NUM>66</CSHR_NUM>
</TC>
<TC diffgr:id="TC2" msdata:rowOrder="1">
<CSHR_POS_NAME>John</CSHR_POS_NAME>
<CSHR_NUM>2</CSHR_NUM>
</TC>
<TC diffgr:id="TC3" msdata:rowOrder="2">
<CSHR_POS_NAME>Jackson</CSHR_POS_NAME>
<CSHR_NUM>3</CSHR_NUM>
</TC>
推荐答案
解决(更改了soap.m):
Solved (changed the soap.m):
[d setObject:v forKey:[child name]];
NSString* key = [child name];
id check = [d objectForKey:key];
if( check != nil ) {
NSInteger next = 1;
key = [NSString stringWithFormat:@"%@%d", [child name], next];
check = [d objectForKey:key];
while( check != nil ) {
next++;
key = [NSString stringWithFormat:@"%@%d", [child name], next];
check = [d objectForKey:key];
}
[d setObject:v forKey:key];
}
[d setObject:v forKey:[child name]];
这篇关于Sudzc deserializeAsDictionary:over writing dictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文