我有这组 xml,我需要保存 price_options 的类别,但是如何保存呢?现在我使用 SWXMLHash,但我不知道如何保存它:
<rss version="2.0">
<channel>
<timestamp>2015-02-27 18:27:21</timestamp>
<tot_record>66</tot_record>
<record>66</record>
<category>NO</category>
<item>
<sku>JC-0000000000594</sku>
<seller>LT Stationery Sdn Bhd</seller>
<seller_logo></seller_logo>
<seller_logo_thumb></seller_logo_thumb>
<name>128PG Foolscap Book -3 Column-HC25511 (RED)</name>
<products_cat>118</products_cat>
<description></description>
<delivery_time>1-2 business days</delivery_time>
<img_1>http://dev.jocom.com.my/images/data/594-img1.jpg</img_1>
<thumb_1>http://dev.jocom.com.my/images/data/thumbs/594-img1.jpg</thumb_1>
<img_2></img_2>
<thumb_2></thumb_2>
<img_3></img_3>
<thumb_3></thumb_3>
<vid_1></vid_1>
<qr_code>JC594</qr_code>
<zone_records>1</zone_records>
<delivery_zones>
<zone>3</zone>
</delivery_zones>
<price_records>1</price_records>
<price_options>
<option>
<id>622</id>
<label>128PG Foolscap Book -3 Column-HC25511 (RED)-BK-3C1200</label>
<price>8.90</price>
<promo_price>0</promo_price>
<qty>10</qty>
<default>TRUE</default>
</option>
</price_options>
</item>
这是我尝试处理的代码,但它不起作用,我应该如何保存子值?:
func searchProducts(){
var id = [String]()
var price = [String]()
let urlString = "http://dev.jocom.com.my/feed"
Alamofire.request(.POST, urlString , parameters: ["req" : "pro_name", "code" : searchString!])
.responseData { response in
switch response.result {
case .Success:
let apiSearchXML = SWXMLHash.parse(response.data!)
print(apiSearchXML)
for elem in apiSearchXML["rss"]["channel"]["item"]["price_options"]["option"] {
id.append(elem["id"].element!.text!)
print("\(id)")
}
case .Failure(let error):
print(error)
}
}
}