0

I got this set of response data:

<delivery_zones>
                <zone>3</zone>
                <zone_name>Within Klang Valley</zone_name>
        </delivery_zones>
<delivery_zones>
                <zone>3</zone>
                <zone_name>Within Klang Valley</zone_name>
        </delivery_zones>
<delivery_zones>
                <zone>3</zone>
                <zone_name>Within Klang Valley</zone_name>
        </delivery_zones>
<delivery_zones>
                <zone>3</zone>
                <zone_name>Within Klang Valley</zone_name>
                <zone>1</zone>
                <zone_name>East Malaysia</zone_name>
                <zone>2</zone>
                <zone_name>Outside Klang Valley</zone_name>
</delivery_zones>

which i wanted to save and display it, here is my code:

for elem3 in elem["delivery_zones"]{

//but is not working, the apps getting crash and this error: fatal error: unexpectedly found nil while unwrapping an Optional value

         self.zone.append(elem3["zone"].element!.text!)     

 }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
bobo
  • 121
  • 2
  • 10
  • which xml parser are you using? – Bista Sep 08 '16 at 07:04
  • Is that the exact response you are receiving as you have shown above, nothing more than that? There should be a root element. And some more code. – Bista Sep 08 '16 at 07:09
  • @Mr.UB yes, this is the exact response that i get, but i cant save it inside array – bobo Sep 08 '16 at 07:18
  • its because elem["delivery_zones"] gives only 1 object here you've to put delivery_zones inside a root object so that it can be parsed as an array – Hamza Ansari Sep 08 '16 at 08:04
  • I checked that the response format is wrong, there should be one root node covering all other nodes i.e your response. – Bista Sep 08 '16 at 12:53

0 Answers0