nicklockwood / XMLDictionary

[DEPRECATED]
http://charcoaldesign.co.uk/source/cocoa#xml-dictionary
Other
1.14k stars 235 forks source link

Issue in parsing an array from XML #45

Open ParthVasavada opened 9 years ago

ParthVasavada commented 9 years ago

Hi,

I am facing an issue while parsing an array with single element in XML. Please refer below example for more details.

<Xml>
    <Item>
        <created_at>Sat Apr 14 00:20:07 +0000 2012</created_at>
        <text>Sample text</text>
        <id_str>190957570511478784</id_str>
    </Item>
    <Item>
        <created_at>Sat Apr 14 00:20:07 +0000 2012</created_at>
        <text>Sample text</text>
       <id_str>190957570511478784</id_str>
    </Item>
</Xml>

If I am going to parse above xml in to dictionary I will get "Item" as an Array. But if there is only single element of "Item" it will be consider as a dictionary. It happen many times when there is a case of getting a single element in array and other time it has multiple elements, e.g location kind of APIs.

How can I manage this case with my objective-c property type? In above case if I take "Item" as NSArray type and in response if I get only single element of "Item" it will be converted to NSDictionary type, and I will get a crash in this case.

Please help me in above scenario and guide me if my understating is not proper.