Я ищу извлечение кода продукта каждого "хита" запроса в виде массива строк: self.rightcode = [code0,code1,code2,...]
Я пытался в течение нескольких дней, но я пытаюсь вставить что-то вроде for i in 1...n
в моей строке ответа String("\(response.value?.resultSet?.the0.result.the[i]?.code ?? "code not found")")
Учитывая следующий запрос Alamofire:
var boncode1: String = ""
func fetch(jan: String) {
let itemSearch = "https://shopping.yahooapis.jp/ShoppingWebService/V1/json/itemSearch?appid=\(appId)&jan=\(jan)&hits=50"
AF.request(itemSearch).responseDecodable(of: Welcome.self) { response in
//load the code product
self.rightcode = String("\(response.value?.resultSet?.the0.result.the0?.code ?? "code not found")")
print(self.rightcode) }
Пожалуйста, найдите ответ json ниже, если он может помочь:
(Я сократил json до 3 случаев: 0,1,2, чтобы не занимать место, но в целом мои запросы достигли 20-50 случаев)
{
"ResultSet": {
"0": {
"Result": {
"0": {
"Name": "東洋ナッツ食品 食塩無添加クラッシー 360g缶 1個",
"Description": "現在ご注文混雑により、日時指定なしのご注文は最大2週間程度お待ちいただく状況です。 商品出荷時にご案内のメール(件名:商品発送のお知らせ)をお送りしておりますので、今しばらくお待ちくださいますようお願い申し上げます。 ※ご注文の確定タイミングにより、在庫が確保できない場合がございます。 「ご注文を確定」する際に再度ご確認ください。 こだわり派の食塩無添加ミックスナッツです 厳選したナッツを使用しています スナック・お菓子 > おつまみ・ドライフルーツ・ナッツ > ドライフルーツ・ナッツ > ドライナッツ",
"Headline": "",
"Url": "https://store.shopping.yahoo.co.jp/y-lohaco/1408892.html",
"ReleaseDate": "",
"Availability": "instock",
"Code": "y-lohaco_1408892",
"Condition": "new",
"Image": {
"Id": "y-lohaco_1408892",
"Small": "https://item-shopping.c.yimg.jp/i/c/y-lohaco_1408892",
"Medium": "https://item-shopping.c.yimg.jp/i/g/y-lohaco_1408892"
},
"Review": {
"Rate": "0.00",
"Count": "1",
"Url": "https://shopping.yahoo.co.jp/review/item/list?store_id=y-lohaco&page_key=1408892"
},
"Affiliate": {
"Rate": "1.0"
},
"Price": {
"_attributes": {
"currency": "JPY"
},
"_value": "1530"
},
"PremiumPrice": "",
"PriceLabel": {
"_attributes": {
"taxIncluded": "true"
},
"FixedPrice": "",
"DefaultPrice": "1530",
"SalePrice": "",
"PremiumPriceStatus": "0",
"PremiumPrice": "1530",
"PremiumDiscountType": "",
"PremiumDiscountRate": "",
"PeriodStart": "",
"PeriodEnd": ""
},
"Point": {
"Amount": "15",
"Times": "1",
"PremiumAmount": "15",
"PremiumTimes": "1"
},
"Shipping": {
"Code": "3",
"Name": "条件付き送料無料"
},
"Category": {
"Current": {
"Id": "4963",
"Name": "ミックスナッツ"
}
},
"CategoryIdPath": {
"0": {
"Id": "1"
},
"1": {
"Id": "2498"
},
"2": {
"Id": "4745"
},
"3": {
"Id": "1161"
},
"4": {
"Id": "4963"
},
"5": {
"Id": "1"
},
"6": {
"Id": "2498"
},
"7": {
"Id": "1313"
},
"8": {
"Id": "14622"
},
"9": {
"Id": "14673"
},
"_container": "Category"
},
"Brands": {
"Name": "",
"Path": {
"0": {
"Id": ""
},
"_container": "Brand"
}
},
"JanCode": "4901998301727",
"Model": "",
"IsbnCode": "",
"Store": {
"Id": "y-lohaco",
"Name": "LOHACO PayPayモール店",
"Url": "https://paypaymall.yahoo.co.jp/store/y-lohaco/top/",
"Payment": {
"0": {
"Code": "1",
"Name": "クレジットカード"
},
"1": {
"Code": "16",
"Name": "Yahoo!ウォレットに登録しているクレジットカード"
},
"2": {
"Code": "4096",
"Name": "PayPay"
},
"_container": "Method"
},
"IsBestStore": "false",
"Ratings": {
"Rate": "4.5",
"Count": "22835",
"Total": "103475",
"DetailRate": "4.5"
},
"Image": {
"Id": "y-lohaco_1",
"Medium": "https://item-shopping.c.yimg.jp/s/h/y-lohaco_1"
},
"IsPMallStore": "true"
},
"IsAdult": "0",
"Deliveryinfo": {
"Area": "",
"Deadline": "",
"Day": ""
},
"_attributes": {
"index": "1"
}
},
"1": {
"Name": "東洋ナッツ食品 食塩無添加 クラッシー ミックスナッツ缶 ( 360g )/ TON'S",
"Description": "東洋ナッツ食品 食塩無添加 クラッシー ミックスナッツ缶(TON Classy)/ドライフルーツ・ナッツ/ブランド:TON'S/【発売元、製造元、輸入元又は販売元】東洋ナッツ食品/(/F214902/F214902/)/【東洋ナッツ食品 食塩無添加 クラッシー ミックスナッツ缶の商品詳細】●無添加タイプのミックスナッツ缶です。●味付けせずに素材を生かすローストで仕上げました。●落花生を配合していません。",
"Headline": "TON'S",
"Url": "https://store.shopping.yahoo.co.jp/kenkocom/e243253h.html",
"ReleaseDate": "",
"Availability": "instock",
"Code": "kenkocom_e243253h",
"Condition": "new",
"Image": {
"Id": "kenkocom_e243253h",
"Small": "https://item-shopping.c.yimg.jp/i/c/kenkocom_e243253h",
"Medium": "https://item-shopping.c.yimg.jp/i/g/kenkocom_e243253h"
},
"Review": {
"Rate": "4.65",
"Count": "65",
"Url": "https://shopping.yahoo.co.jp/review/item/list?store_id=kenkocom&page_key=e243253h"
},
"Affiliate": {
"Rate": "1.0"
},
"Price": {
"_attributes": {
"currency": "JPY"
},
"_value": "1458"
},
"PremiumPrice": "",
"PriceLabel": {
"_attributes": {
"taxIncluded": "true"
},
"FixedPrice": "",
"DefaultPrice": "1458",
"SalePrice": "",
"PremiumPriceStatus": "0",
"PremiumPrice": "1458",
"PremiumDiscountType": "",
"PremiumDiscountRate": "",
"PeriodStart": "",
"PeriodEnd": ""
},
"Point": {
"Amount": "14",
"Times": "1",
"PremiumAmount": "14",
"PremiumTimes": "1"
},
"Shipping": {
"Code": "3",
"Name": "条件付き送料無料"
},
"Category": {
"Current": {
"Id": "4963",
"Name": "ミックスナッツ"
}
},
"CategoryIdPath": {
"0": {
"Id": "1"
},
"1": {
"Id": "2498"
},
"2": {
"Id": "4745"
},
"3": {
"Id": "1161"
},
"4": {
"Id": "4963"
},
"5": {
"Id": "1"
},
"6": {
"Id": "2498"
},
"7": {
"Id": "1313"
},
"8": {
"Id": "14622"
},
"9": {
"Id": "14673"
},
"_container": "Category"
},
"Brands": {
"Name": "",
"Path": {
"0": {
"Id": ""
},
"_container": "Brand"
}
},
"JanCode": "4901998301727",
"Model": "",
"IsbnCode": "",
"Store": {
"Id": "kenkocom",
"Name": "ケンコーコム",
"Url": "https://store.shopping.yahoo.co.jp/kenkocom/",
"Payment": {
"0": {
"Code": "1",
"Name": "クレジットカード"
},
"1": {
"Code": "16",
"Name": "Yahoo!ウォレットに登録しているクレジットカード"
},
"2": {
"Code": "4",
"Name": "商品代引"
},
"3": {
"Code": "4096",
"Name": "PayPay"
},
"_container": "Method"
},
"IsBestStore": "false",
"Ratings": {
"Rate": "4.5",
"Count": "240786",
"Total": "1068536",
"DetailRate": "4.4"
},
"Image": {
"Id": "kenkocom_1",
"Medium": "https://item-shopping.c.yimg.jp/s/h/kenkocom_1"
},
"IsPMallStore": "false"
},
"IsAdult": "0",
"Deliveryinfo": {
"Area": "",
"Deadline": "",
"Day": ""
},
"_attributes": {
"index": "2"
}
},
"2": {
"Name": "東洋ナッツ食品 食塩無添加 クラッシーミックスナッツ缶 360g 1缶",
"Description": "メーカー:東洋ナッツ食品 品番:740819 持ち味の違う6つのナッツをミックスしました。人気の食塩無添加タイプ。",
"Headline": "【1回のご注文が税込3,000円以上で送料無料!(沖縄を除く)】",
"Url": "https://store.shopping.yahoo.co.jp/tanomail/0678982.html",
"ReleaseDate": "",
"Availability": "instock",
"Code": "tanomail_0678982",
"Condition": "new",
"Image": {
"Id": "tanomail_0678982",
"Small": "https://item-shopping.c.yimg.jp/i/c/tanomail_0678982",
"Medium": "https://item-shopping.c.yimg.jp/i/g/tanomail_0678982"
},
"Review": {
"Rate": "4.57",
"Count": "7",
"Url": "https://shopping.yahoo.co.jp/review/item/list?store_id=tanomail&page_key=0678982"
},
"Affiliate": {
"Rate": "1.0"
},
"Price": {
"_attributes": {
"currency": "JPY"
},
"_value": "1497"
},
"PremiumPrice": "",
"PriceLabel": {
"_attributes": {
"taxIncluded": "true"
},
"FixedPrice": "",
"DefaultPrice": "1497",
"SalePrice": "",
"PremiumPriceStatus": "0",
"PremiumPrice": "1497",
"PremiumDiscountType": "",
"PremiumDiscountRate": "",
"PeriodStart": "",
"PeriodEnd": ""
},
"Point": {
"Amount": "14",
"Times": "1",
"PremiumAmount": "14",
"PremiumTimes": "1"
},
"Shipping": {
"Code": "3",
"Name": "条件付き送料無料"
},
"Category": {
"Current": {
"Id": "13451",
"Name": "その他スナック、お菓子、おつまみ"
}
},
"CategoryIdPath": {
"0": {
"Id": "1"
},
"1": {
"Id": "2498"
},
"2": {
"Id": "4745"
},
"3": {
"Id": "13451"
},
"_container": "Category"
},
"Brands": {
"Name": "",
"Path": {
"0": {
"Id": ""
},
"_container": "Brand"
}
},
"JanCode": "4901998301727",
"Model": "740819",
"IsbnCode": "",
"Store": {
"Id": "tanomail",
"Name": "ぱーそなるたのめーる",
"Url": "https://paypaymall.yahoo.co.jp/store/tanomail/top/",
"Payment": {
"0": {
"Code": "1",
"Name": "クレジットカード"
},
"1": {
"Code": "16",
"Name": "Yahoo!ウォレットに登録しているクレジットカード"
},
"2": {
"Code": "4",
"Name": "商品代引"
},
"3": {
"Code": "4096",
"Name": "PayPay"
},
"_container": "Method"
},
"IsBestStore": "true",
"Ratings": {
"Rate": "4.5",
"Count": "37923",
"Total": "172500",
"DetailRate": "4.5"
},
"Image": {
"Id": "tanomail_1",
"Medium": "https://item-shopping.c.yimg.jp/s/h/tanomail_1"
},
"IsPMallStore": "true"
},
"IsAdult": "0",
"Deliveryinfo": {
"Area": "",
"Deadline": "",
"Day": ""
},
"_attributes": {
"index": "3"
}
},
"Request": {
"Query": ""
},
"Modules": "",
"_container": "Hit"
}
},
"totalResultsAvailable": "30",
"totalResultsReturned": 30,
"firstResultPosition": "1"
}
}