How to add/insert element in array one after another like stack swift 5

前端 未结 2 905
情书的邮戳
情书的邮戳 2021-01-24 06:02

I get String from api response and stored in an array.

     for customParams in custom_attributes! {
         if(customParams[\"attribute_code\"] as! String == \         


        
2条回答
  •  心在旅途
    2021-01-24 06:42

    You need to loop through the items array first as it is in json, also declare myArray outside the for loop and start appending myString inside myArray as shown:

    var myArray :[String] = []
    for custom_attributes! in items { // items is the json items array
        for customParams in custom_attributes! {
            if(customParams["attribute_code"] as! String == "small_image") 
                 {
                 print(customParams["value"])
                 var myString = customParams["value"] as! String
                 myArray.append(myString)
    
             }
         }
     }
    

提交回复
热议问题