Ios 对象的问题
我在iOS中做一些简单的事情有困难。我正在解析一个XML,我想用我检索到的数据填充一个对象Ios 对象的问题,ios,xml,object,tbxml,Ios,Xml,Object,Tbxml,我在iOS中做一些简单的事情有困难。我正在解析一个XML,我想用我检索到的数据填充一个对象 do { TBXMLAttribute * attribute = element->firstAttribute; while (attribute) { Position *position = [[Position alloc]init]; if ([[TBXML elementName:element] isEqualToString
do {
TBXMLAttribute * attribute = element->firstAttribute;
while (attribute) {
Position *position = [[Position alloc]init];
if ([[TBXML elementName:element] isEqualToString:@"referencecolis"]) {
[position.cab addObject:[TBXML textForElement:element]];
NSLog(@"array cab : %@",position.cab);
};
};
if ([[TBXML elementName:element] isEqualToString:@"idagencedepart"]) {
position.idagencedepart = [TBXML textForElement:element];
NSLog(@"idagencedepart : %@",[TBXML textForElement:element]);
};
[arrayPositions addObject:position];
attribute = attribute->next;
}
if (element->firstChild)
[self traverseElement:element->firstChild];
} while ((element = element->nextSibling));
“[position.cab addObject:[TBXML textforement:element]];”应该将xml的几个“referencecoli”添加到我的类“position”中声明的数组中
当我打印包含所有位置对象的数组时,它是空的
我做错了什么
以下是xml中与我的问题有关的部分:
<idagencefinale type="java.lang.Integer">4</idagencefinale>
<idclientreglantport type="java.lang.Integer">38201</idclientreglantport>
<idcomptefacturation type="java.lang.Integer">15596</idcomptefacturation>
<idconditiontaxation type="java.lang.Integer">13109</idconditiontaxation>
<idconditiontaxationgeneral type="java.lang.Integer">13109</idconditiontaxationgeneral>
<iddestinataire type="java.lang.Integer">40245</iddestinataire>
<idexpediteur type="java.lang.Integer">38201</idexpediteur>
<idfeuillechauffeur type="java.lang.Integer"/>
<idfluxedi type="java.lang.Integer">143821</idfluxedi>
<idforfaitechelle type="java.lang.Integer"/>
<idgroupage type="java.lang.Integer"/>
<idlocalitedestinataire type="java.lang.Integer">196</idlocalitedestinataire>
<idlocaliteexpediteur type="java.lang.Integer">250</idlocaliteexpediteur>
<idpositionapproche type="java.lang.Integer"/>
<idpositionlivraison type="java.lang.Integer"/>
<idpositionprecedente type="java.lang.Integer"/>
<idreleveassignecompte type="java.lang.Integer"/>
<idreleveassignecompteReexpedition type="java.lang.Integer"/>
<idreleveportducompte type="java.lang.Integer"/>
<idreleveportducompteReexpedition type="java.lang.Integer"/>
<idremise type="java.lang.Integer"/>
<idremisegeneral type="java.lang.Integer"/>
<idserviceechelle type="java.lang.Integer"/>
<idtarif type="java.lang.Integer">48271</idtarif>
<idtarifgeneral type="java.lang.Integer">48271</idtarifgeneral>
<idtiers type="java.lang.Integer"/>
<iduser type="java.lang.Integer">498</iduser>
<libellePort type="java.lang.String">PORT PAYE</libellePort>
<locked type="boolean">false</locked>
<lockedByFacturation type="boolean">false</lockedByFacturation>
<longueur type="java.math.BigDecimal"/>
<motifannulation type="java.lang.String"/>
<origine type="java.lang.String">edi</origine>
<palette type="java.lang.Integer">0</palette>
<paletteConsignee type="java.lang.Integer">0</paletteConsignee>
<poids type="java.math.BigDecimal">181.0000</poids>
<poidsPalette type="java.math.BigDecimal">0.0000</poidsPalette>
<poidsTotal type="java.math.BigDecimal">181.0000</poidsTotal>
<port type="java.lang.Integer">0</port>
<portDuRegle type="boolean">false</portDuRegle>
<positionAdresseList type="java.util.Collection">
<Object hashcode="75b25" type="fezfsfs.position.PositionAdresse">
<adresse1 type="java.lang.String">fezfezfz</adresse1>
<adresse2 type="java.lang.String">Zfezfzfezf</adresse2>
<adresse3 type="java.lang.String"/>
<codepostal type="java.lang.String">01700</codepostal>
<datecreation type="java.util.Date">2013-09-06 17:44:12.268</datecreation>
<datemodification type="java.util.Date"/>
<datesuppression type="java.util.Date"/>
<deleted type="boolean">false</deleted>
<id type="java.lang.Integer">482085</id>
<idlocalite type="java.lang.Integer">250</idlocalite>
<iduser type="java.lang.Integer">498</iduser>
<pays type="java.lang.String">FRANCE</pays>
<position hashcode="3aba5" type="ffezfezfezfze.position.Position"/>
<raisonsociale type="java.lang.String">fezfezfezfez</raisonsociale>
<typeadresse type="java.lang.Integer">0</typeadresse>
<ville type="java.lang.String">fezfez</ville>
</Object>
<Object hashcode="75b26" type="fr.truckinfo.etreck.hibernate.core.position.PositionAdresse">
<adresse1 type="java.lang.String">fezfezfzfze</adresse1>
<adresse2 type="java.lang.String">fezfezfze</adresse2>
<adresse3 type="java.lang.String"/>
<codepostal type="java.lang.String">01480</codepostal>
<datecreation type="java.util.Date">2013-09-06 17:44:12.268</datecreation>
<datemodification type="java.util.Date"/>
<datesuppression type="java.util.Date"/>
<deleted type="boolean">false</deleted>
<id type="java.lang.Integer">482086</id>
<idlocalite type="java.lang.Integer">196</idlocalite>
<iduser type="java.lang.Integer">498</iduser>
<pays type="java.lang.String">FRANCE</pays>
<position hashcode="3aba5" type="kofkeokfoezfpezf.position.Position"/>
<raisonsociale type="java.lang.String">foofejozjfoejfoezjfez_</raisonsociale>
<typeadresse type="java.lang.Integer">1</typeadresse>
<ville type="java.lang.String">kfoekofkeoe</ville>
</Object>
</positionAdresseList>
<positionAffectationChauffeursList type="java.util.Collection"/>
<positionAffretementList type="java.util.Collection"/>
<positionCRTList type="java.util.Collection"/>
<positionColisList type="java.util.Collection">
<Object hashcode="f6ed9" type="fr.truckinfo.etreck.hibernate.core.position.PositionColis">
<complement type="java.lang.String">000000340863000642886657</complement>
<dateaffectation type="java.util.Date">2013-09-06 13:36:33.052</dateaffectation>
<datecreation type="java.util.Date"/>
<datemodification type="java.util.Date"/>
<datesuppression type="java.util.Date"/>
<deleted type="boolean">false</deleted>
<id type="java.lang.Integer">1011417</id>
<idfluxedicolis type="java.lang.Integer">633374</idfluxedicolis>
<iduser type="java.lang.Integer"/>
<poids type="java.math.BigDecimal">0.000</poids>
<position hashcode="3aba5" type="*****.position.Position"/>
<referencecolis type="java.lang.String">000000340863000642886657</referencecolis>
<typeaffectation type="java.lang.String"/>
</Object>
</positionColisList>
4
38201
15596
13109
13109
40245
38201
143821
196
250
48271
48271
498
PAYE港
假的
假的
电子数据交换
0
0
181
0
181
0
假的
fezfezfz
Zfezfzfezf
01700
2013-09-06 17:44:12.268
假的
482085
250
498
法国
菲兹菲兹
0
费兹菲兹
fezfezfzfze
fezfezfze
01480
2013-09-06 17:44:12.268
假的
482086
196
498
法国
foofejozjfoejfoezjfez_
1.
kfoekofkeoe
000000340863000642886657
2013-09-06 13:36:33.052
假的
1011417
633374
0
000000340863000642886657
如果数组为空,则是解析问题。如果您的数组为nill,则可能是因为您没有对其进行alloc/init。该数组被分配为“NSMutableArray*arrayPositions=[[NSMutableArray alloc]init];”,while循环中的位置对象。NSLogs可以很好地打印解析后的数据。逐步检查代码,不时在调试器中键入“po position.cab”,然后观察数组的增长。您没有显示打印出来的位置,但是否有可能您以后没有使用它,而ARC因为您不再需要它而将其丢弃?如果它是属性,请确保您使用的是@property(强,非原子)。Position对象为空,而NSLog显示xml解析良好。包含所有Positions对象的数组(一个属性(强,非原子))会增长,但Position对象为空。我发现问题是,“Position.cab=”很愚蠢,“Position setCab”更好。。。