Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
Arrays 斯威夫特穆尔蒂电平滤波_Arrays_Json_Swift_Filter - Fatal编程技术网

Arrays 斯威夫特穆尔蒂电平滤波

Arrays 斯威夫特穆尔蒂电平滤波,arrays,json,swift,filter,Arrays,Json,Swift,Filter,我有上面的json。我想要的是使用过滤器来获取对象的详细信息,只针对那些颜色为金色且存储空间为64 gb的对象。可以通过过滤器实现吗?对于第一级过滤,它对我来说很好,如下所示: { "productId" : "prod830028", "deviceFeatures" : [ "SIM Type:Nano", "Battery:3,174mAh", "Front Camera:7MP", "Rear Cam

我有上面的json。我想要的是使用过滤器来获取对象的详细信息,只针对那些颜色为金色且存储空间为64 gb的对象。可以通过过滤器实现吗?对于第一级过滤,它对我来说很好,如下所示:

    {
    "productId" : "prod830028",
    "deviceFeatures" : [
        "SIM Type:Nano",
        "Battery:3,174mAh",
        "Front Camera:7MP",
        "Rear Camera:12MP + 12MP",
        "OS:iOS 12",
        "Processor:A12 Bionic chip with next-generation Neural Engine",
        "Display:6.5 inches, OLED"
    ],

    "productOverView": "Meet the iPhone X - the device that’s so smart that it responds to a tap, your voice, and even a glance. Elegantly designed with a large 14.73 cm (5.8) Super Retina screen and a durable front-and-back glass.",
    "specifications":[
        {
            "key": "Color",
            "value": "Space Grey"
        },
        {
            "key": "Internal Memory",
            "value": "64 GB"
        },
        {
            "key": "Operating System",
            "value": "iOS 11.1.1"
        },
        {
            "key": "Primary Camera",
            "value": "12 MP"
        },
        {
            "key": "RAM",
            "value": "5.8 inch"
        },
        {
            "key": "Screen Size",
            "value": "15"
        },
        {
            "key": "Expandable Memory",
            "value": "No"
        },
        {
            "key": "Camera Feature",
            "value": "Geo-tagging, simultaneous 4K video and 8MP image recording, touch focus, face/smile detection, HDR (photo/panorama)"
        }
    ],
    "preorderable" : false,
    "responseMsg" : "SUCCESS",
    "skuDetails" : [
        {
            "oldPriceWithVat" : "4461.45",
            "pointsWithVat" : "393900",
            "pointsWithoutVat" : "375143",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9F",
            "priceWithouthVat" : "3751.43",
            "priceWithVat" : "3939.0015",
            "devicePaymentOptions" : [
                {
                    "price" : "362.0",
                    "duration" : "12",
                    "demandId" : "3052451"
                },
                {
                    "price" : "185.0",
                    "duration" : "24",
                    "demandId" : "3052468"
                },
                {
                    "price" : "244.0",
                    "duration" : "18",
                    "demandId" : "3052593"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202391",
            "vatPercentage" : "5",
            "sicCode" : "3820202391",
            "oldPriceWithoutVat" : "4249.0",
            "oldPricePointsWithoutVat" : "424900",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-SpaceGray-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#8C8C8C",
                    "value" : "Space Gray",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "64GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "446145",
            "demandId" : "3060416"
        },
        {
            "oldPriceWithVat" : "4461.45",
            "pointsWithVat" : "316575",
            "pointsWithoutVat" : "301500",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9I",
            "priceWithouthVat" : "3015.0",
            "priceWithVat" : "3165.75",
            "devicePaymentOptions" : [
                {
                    "price" : "362.0",
                    "duration" : "12",
                    "demandId" : "3052402"
                },
                {
                    "price" : "185.0",
                    "duration" : "24",
                    "demandId" : "3052634"
                },
                {
                    "price" : "244.0",
                    "duration" : "18",
                    "demandId" : "3052559"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202404",
            "vatPercentage" : "5",
            "sicCode" : "3820202404",
            "oldPriceWithoutVat" : "4249.0",
            "oldPricePointsWithoutVat" : "424900",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-Silver-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#C0C0C0",
                    "value" : "Silver",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "64GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "446145",
            "demandId" : "3060419"
        },
        {
            "oldPriceWithVat" : "4461.45",
            "pointsWithVat" : "393900",
            "pointsWithoutVat" : "375143",
            "ratePlanCode" : "RPDLAPAPPEQ000000GAL",
            "priceWithouthVat" : "3751.43",
            "priceWithVat" : "3939.0015",
            "devicePaymentOptions" : [
                {
                    "price" : "185.0",
                    "duration" : "24",
                    "demandId" : "3052605"
                },
                {
                    "price" : "362.0",
                    "duration" : "12",
                    "demandId" : "3052640"
                },
                {
                    "price" : "244.0",
                    "duration" : "18",
                    "demandId" : "3052646"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202419",
            "vatPercentage" : "5",
            "sicCode" : "3820202419",
            "oldPriceWithoutVat" : "4249.0",
            "oldPricePointsWithoutVat" : "424900",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-Gold-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#D4AF37",
                    "value" : "Gold",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "64GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "446145",
            "demandId" : "3060494"
        },
        {
            "oldPriceWithVat" : "5065.2",
            "pointsWithVat" : "445500",
            "pointsWithoutVat" : "424286",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9E",
            "priceWithouthVat" : "4242.86",
            "priceWithVat" : "4455.003",
            "devicePaymentOptions" : [
                {
                    "price" : "210.0",
                    "duration" : "24",
                    "demandId" : "3052406"
                },
                {
                    "price" : "277.0",
                    "duration" : "18",
                    "demandId" : "3052372"
                },
                {
                    "price" : "411.0",
                    "duration" : "12",
                    "demandId" : "3052571"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202438",
            "vatPercentage" : "5",
            "sicCode" : "3820202438",
            "oldPriceWithoutVat" : "4824.0",
            "oldPricePointsWithoutVat" : "482400",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-SpaceGray-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#8C8C8C",
                    "value" : "Space Gray",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "256GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "506520",
            "demandId" : "3060415"
        },
        {
            "oldPriceWithVat" : "5065.2",
            "pointsWithVat" : "445500",
            "pointsWithoutVat" : "424286",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9Y",
            "priceWithouthVat" : "4242.86",
            "priceWithVat" : "4455.003",
            "devicePaymentOptions" : [
                {
                    "price" : "210.0",
                    "duration" : "24",
                    "demandId" : "3052650"
                },
                {
                    "price" : "411.0",
                    "duration" : "12",
                    "demandId" : "3052353"
                },
                {
                    "price" : "277.0",
                    "duration" : "18",
                    "demandId" : "3052520"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202453",
            "vatPercentage" : "5",
            "sicCode" : "3820202453",
            "oldPriceWithoutVat" : "4824.0",
            "oldPricePointsWithoutVat" : "482400",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-Silver-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#C0C0C0",
                    "value" : "Silver",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "256GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "506520",
            "demandId" : "3060445"
        },
        {
            "oldPriceWithVat" : "5065.2",
            "pointsWithVat" : "445500",
            "pointsWithoutVat" : "424286",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9B",
            "priceWithouthVat" : "4242.86",
            "priceWithVat" : "4455.003",
            "devicePaymentOptions" : [
                {
                    "price" : "411.0",
                    "duration" : "12",
                    "demandId" : "3052561"
                },
                {
                    "price" : "277.0",
                    "duration" : "18",
                    "demandId" : "3052510"
                },
                {
                    "price" : "210.0",
                    "duration" : "24",
                    "demandId" : "3052448"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202469",
            "vatPercentage" : "5",
            "sicCode" : "3820202469",
            "oldPriceWithoutVat" : "4824.0",
            "oldPricePointsWithoutVat" : "482400",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-Gold-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#D4AF37",
                    "value" : "Gold",
                    "key" : "Colour",
                    "displayText" : "Colour"
                }
            ],
            "oldPricePointsWithVat" : "506520",
            "demandId" : "3060412"
        },
        {
            "oldPriceWithVat" : "5884.2",
            "pointsWithVat" : "525500",
            "pointsWithoutVat" : "500476",
            "ratePlanCode" : "RPDLAPAPPEQ000000GA0",
            "priceWithouthVat" : "5004.76",
            "priceWithVat" : "5254.9980000000005",
            "devicePaymentOptions" : [
                {
                    "price" : "336.0",
                    "duration" : "18",
                    "demandId" : "3052601"
                },
                {
                    "price" : "499.0",
                    "duration" : "12",
                    "demandId" : "3052569"
                },
                {
                    "price" : "255.0",
                    "duration" : "24",
                    "demandId" : "3052361"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202486",
            "vatPercentage" : "5",
            "sicCode" : "3820202486",
            "oldPriceWithoutVat" : "5604.0",
            "oldPricePointsWithoutVat" : "560400",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-SpaceGray-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#8C8C8C",
                    "value" : "Space Gray",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "512GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "588420",
            "demandId" : "3060451"
        },
        {
            "oldPriceWithVat" : "5884.2",
            "pointsWithVat" : "525500",
            "pointsWithoutVat" : "500476",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9O",
            "priceWithouthVat" : "5004.76",
            "priceWithVat" : "5254.9980000000005",
            "devicePaymentOptions" : [
                {
                    "price" : "255.0",
                    "duration" : "24",
                    "demandId" : "3052466"
                },
                {
                    "price" : "499.0",
                    "duration" : "12",
                    "demandId" : "3052319"
                },
                {
                    "price" : "336.0",
                    "duration" : "18",
                    "demandId" : "3052334"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202505",
            "vatPercentage" : "5",
            "sicCode" : "3820202505",
            "oldPriceWithoutVat" : "5604.0",
            "oldPricePointsWithoutVat" : "560400",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-Silver-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#C0C0C0",
                    "value" : "Silver",
                    "key" : "Colour",
                    "displayText" : "Colour"
                },
                {
                    "key" : "Storage",
                    "value" : "512GB",
                    "displayText" : "Storage"
                },
                {
                    "key" : "Memory",
                    "value" : "4GB RAM",
                    "displayText" : "Memory"
                }
            ],
            "oldPricePointsWithVat" : "588420",
            "demandId" : "3060427"
        },
        {
            "oldPriceWithVat" : "5884.2",
            "pointsWithVat" : "525500",
            "pointsWithoutVat" : "500476",
            "ratePlanCode" : "RPDLAPAPPEQ000000G9S",
            "priceWithouthVat" : "5004.76",
            "priceWithVat" : "5254.9980000000005",
            "devicePaymentOptions" : [
                {
                    "price" : "499.0",
                    "duration" : "12",
                    "demandId" : "3052340"
                },
                {
                    "price" : "336.0",
                    "duration" : "18",
                    "demandId" : "3052613"
                },
                {
                    "price" : "255.0",
                    "duration" : "24",
                    "demandId" : "3052324"
                }
            ],
            "payWithPointAvailable" : false,
            "skuId" : "bgSku3820202524",
            "vatPercentage" : "5",
            "sicCode" : "3820202524",
            "oldPriceWithoutVat" : "5604.0",
            "oldPricePointsWithoutVat" : "560400",
            "cashOnDeliveryAvailable" : true,
            "images" : [
                "https:\/\/www.etisalat.ae\/en\/system\/wst\/assets\/img\/devices\/AP-iPhoneXSMax\/AP-iPhoneXsMax-Gold-PureAngles-500.jpg"
            ],
            "skuCoreProperties" : [
                {
                    "colorCode" : "#D4AF37",
                    "value" : "Gold",
                    "key" : "Colour",
                    "displayText" : "Colour"
                }
            ],
            "oldPricePointsWithVat" : "588420",
            "demandId" : "3060430"
        }
    ],
    "brand" : "Apple",
    "responseCode" : "0000000",
    "name" : "iPhone XS Max"
}
但我无法解析上述条件下的数据,如果无法通过谓词或任何其他方法实现,请告诉我

**

  • 更新:显示这些模型的类
**

类SWSKU详细信息:可编码{

class SWGetDeviceSKUsAndDetailsResponseModel : SWBaseResponseModel {

    let brand : String?
    let deviceFeatures : [String]?
    let name : String?
    let preorderable : Bool?
    let productId : String?
    let productOverView : String?
    let skuDetails : [SWSkuDetail]?
    let specifications : [SWSpecification]?

}
let cashOnDeliveryAvailable : Bool?
let demandId : String?
let devicePaymentOptions : [SWDevicePaymentOption]?
let images : [String]?
let oldPricePointsWithVat : String?
let oldPricePointsWithoutVat : String?
let oldPriceWithVat : String?
let oldPriceWithoutVat : String?
let payWithPointAvailable : Bool?
let pointsWithVat : String?
let pointsWithoutVat : String?
let priceWithVat : String?
let priceWithouthVat : String?
let ratePlanCode : String?
let sicCode : String?
let skuCoreProperties : [SWSkuCoreProperty]?
let skuId : String?
let vatPercentage : String?
}

类SWSkuCoreProperty:可编码{

class SWGetDeviceSKUsAndDetailsResponseModel : SWBaseResponseModel {

    let brand : String?
    let deviceFeatures : [String]?
    let name : String?
    let preorderable : Bool?
    let productId : String?
    let productOverView : String?
    let skuDetails : [SWSkuDetail]?
    let specifications : [SWSpecification]?

}
let cashOnDeliveryAvailable : Bool?
let demandId : String?
let devicePaymentOptions : [SWDevicePaymentOption]?
let images : [String]?
let oldPricePointsWithVat : String?
let oldPricePointsWithoutVat : String?
let oldPriceWithVat : String?
let oldPriceWithoutVat : String?
let payWithPointAvailable : Bool?
let pointsWithVat : String?
let pointsWithoutVat : String?
let priceWithVat : String?
let priceWithouthVat : String?
let ratePlanCode : String?
let sicCode : String?
let skuCoreProperties : [SWSkuCoreProperty]?
let skuId : String?
let vatPercentage : String?

以下代码将返回任何颜色为金色且存储容量为64 GB的
SWSkuDetail

filter函数首先用给定的键过滤掉元素,然后检查它是否得到了2次点击,以及这两个值是否都存在

let colorCode : String?
let displayText : String?
let key : String?
let value : String?

}

如果您想获得筛选结构层次结构数组的帮助,您应该发布结构层次结构的代码,而不是json数据。@JoakimDanielson为模型添加了类以获得更多解释哇,这是一个很棒的工作,就像它的魅力一样。我还需要知道一件事:let array=props.filter{$0.key==keyColor | |$0.key==keystrage}.map{$0.value}如果加上颜色和存储,我也有其他核心属性的键值对,比如内存、双卡e.t.c.有没有更好的方法来代替使用硬编码的键值和键值存储。意思是说,我可以不指定任何键值而只根据值获得swskudetail???@JoakimDanielson@SyedFarazHaiderZaidi你可以把我t转换为一个以搜索参数为参数的函数。可能是以字典的形式,但我如何才能做到这一点?请也帮我解决这个问题。@SyedFarazHaiderZaidi我在你的第二条评论中看到,你现在只想对值进行筛选,而不想对键/值对进行筛选,所以感觉这是一个全新的问题。你可以跳过这个问题然后对键进行过滤,并直接使用
映射
,然后对值使用
包含
。可能将值放在一个数组中,并在循环中检查每个值