ios - Value stored in array but not accessable? -
i have sorted web api , stored value key "attributevalue" in array while accessing doesnot show sugestion
{ "responsemsg": "successfull", "responsecode": "200", "data": { "sku": "arv-95x103535", "description": "<p>watercolor on paper</p>\r\n", "shortdescription": "", "prodattribute": [ { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "10", "lablename": " height inch", "fk_elementdetailid": 12, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "9.5", "lablename": " width inch", "fk_elementdetailid": 13, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "n.a", "lablename": " year ", "fk_elementdetailid": 15, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "water color on paper", "lablename": " medium ", "fk_elementdetailid": 16, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "right bottom", "lablename": " signature position ", "fk_elementdetailid": 17, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "canvas", "lablename": " surface ", "fk_elementdetailid": 19, "isrequired": true } ] this parsing code
let jsonproductattributes = jsonresult!["data"]!["prodattribute"] as! [anyobject] print("the product arrtibutes are",jsonproductattributes) var artattributesarry = [details]() attri in jsonproductattributes { let artdetails = details(); artdetails.values = attri["attributevalue"]as! string artattributesarry.append(artdetails) print("the attributed values ",attri["attributevalue"]as! string) } this model class
class detailproduct { var attributes: [details]! } class details { var values: string! } any suggestion helpful if alteration or changes in codes
thank
your json missing, @ end:
} } the following i've tested alamofire , swiftyjson, works:
import foundation import alamofire import swiftyjson class apiwrapper { func getjson() { print("making request"); alamofire.request(.get, "http://localhost:8000/swift") .responsejson { (request, response, result) -> void in if let value = result.value { let json = json(value) self.parsejson(json) } } } func parsejson(json: json) { result in json["data"]["prodattribute"].arrayvalue { print(result["attributevalue"].stringvalue) } } } with following json:
{ "responsemsg": "successfull", "responsecode": "200", "data": { "sku": "arv-95x103535", "description": "<p>watercolor on paper</p>\r\n", "shortdescription": "", "prodattribute": [ { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "10", "lablename": " height inch", "fk_elementdetailid": 12, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "9.5", "lablename": " width inch", "fk_elementdetailid": 13, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "n.a", "lablename": " year ", "fk_elementdetailid": 15, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "water color on paper", "lablename": " medium ", "fk_elementdetailid": 16, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "right bottom", "lablename": " signature position ", "fk_elementdetailid": 17, "isrequired": true }, { "attrkeyvalue": "", "fk_categoryid": 78, "colorimgpath": "", "attributevalue": "canvas", "lablename": " surface ", "fk_elementdetailid": 19, "isrequired": true } ] } }
Comments
Post a Comment