Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我想获取产品描述,但它包含html,所以我弄不清楚如何从中获取正确的格式_Ios_Json_Swift - Fatal编程技术网

Ios 我想获取产品描述,但它包含html,所以我弄不清楚如何从中获取正确的格式

Ios 我想获取产品描述,但它包含html,所以我弄不清楚如何从中获取正确的格式,ios,json,swift,Ios,Json,Swift,JSON: 是的,您正在做同样的事情,但是您的代码很容易崩溃,因为您正在强制尝试展开选项。试试这个 { "wishlist": [ { "wishlist": 0 } ], "cart": [ { "cart": 1 } ], "product": [ { "promo_id": 0, "avals": 0, "dis": null, "mp_product_id": 252, "mp_category_id": 113, "product_name": "Pink Soft Net Fabri

JSON:


是的,您正在做同样的事情,但是您的代码很容易崩溃,因为您正在强制尝试展开选项。试试这个

{ "wishlist": [ { "wishlist": 0 } ], "cart": [ { "cart": 1 } ], "product": [ { "promo_id": 0, "avals": 0, "dis": null, "mp_product_id": 252, "mp_category_id": 113, "product_name": "Pink Soft Net Fabric Kids Angel Lehenga Choli", "product_description": " This Pink Coloured Traditional Soft Net Fabric Lehenga Choli gives a beautifull look to your child. This Outfit come with Brocket Fabric Lehenga and Top has Soft Net Fabric with Silk Lining come along with Soft Net Dupatta .\r\n\r\n You can make your kids wear this outfit for parties and functions.\r\n\r\n Type :\r\n\r\n *Semi-Stitched*\r\n\r\n FABRIC :\r\n\r\n Top : Unstitched Designer Brocade fabric \r\nBottom : stitched Soft Net fabric \r\nDupatta : Soft Net fabric \r\nInner : Silk fabric\r\n\r\n Size Chart :\r\n\r\n 1 to 5 year : 30 inches \r\n6 to 8 year : 32 inches \r\n9 to 10 year : 34 inches \r\n10 to 15 year: 36 inches\r\n\r\n Care \r\nDry Clean\r\n", "sku_number": "Angel_3_Pink", "qty": 25, "likes_count": 0, "list_price": 2082, "selling_price": 1249, "discount": 41 } ], "image": [ { "image_name": "Sweet Angel Vol3-Pink.jpg" } ], "variant": [ { "Color": "PINK", "Size": "S,M,L,XL", "Occasion": "Party" } ], "related": [ { "mp_product_id": 231, "mp_category_id": 113, "product_name": "White Peacock Kids Indo Western ", "product_description": " This White Coloured Traditional Banglory Top Fabrics Indo Western gives a beautifull look to your child. This Outfit come with Paper Silk Fabric Lehenga and Top has Banglory Fabric.\r\n\r\n You can make your kids wear this outfit for parties and functions.\r\n\r\n Type :\r\n\r\n *Stitched*\r\n\r\n FABRIC :\r\n\r\n Top - Banglory (foam seat work),\r\n\r\n Lehenga - Paper silk,\r\n\r\n Size Chart :\r\n\r\n 6 to 12 year : 34 inches\r\n\r\n Care \r\nDry Clean\r\n", "product_image": "", "seller_product_code": "White_Peacock", "system_product_code": 0, "sku_number": "White_Peacock", "status": "A", "is_features": 0, "list_price": 2271, "selling_price": 1249, "qty": 25, "weight": "700", "cod_charge": "0", "shipping_charge": "0", "likes_count": 0, "create_date": "2017-06-26 12:38:51", "modify_date": "2017-06-26 12:39:37", "main_order": 14, "set_order": 0, "image_name": "Peacock White Kids \u00a0--- CKL 216 --- Rs. 625.jpg" }
先生,我正在使用almofire调用json我的代码看起来像Alamofire.requestAPIProductDetail,方法:.get,参数:params,编码:URLEncoding.default.responseJSON{response in self.result=response.result.value as!NSDictionary let Str2=self.result.valueforKey:productas!NSArray let Product_Description=Str2.objectat:0 as AnyObject.valueforKey:Product_Description as!String}@用户8198079,我已经用Alamofire更新了我的代码。你也做了同样的事情。请试试上面的
Alamofire.request(APIProductDetail, method: .get, parameters: params, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in

        switch response.result {
        case .success(let responseResultValue):
            if let responseResult = responseResultValue as? [String:Any] {
                if let productsList = responseResult["product"] as? [[String:Any]] {
                    for product in productsList {
                        if let productDescription = product["product_description"] as? String {
                            print(productDescription)  //Here you will get the product description
                        }
                    }
                }

            }

        case .failure(let error):
            //handle any error here
            print(error.localizedDescription)
        }

    }