小编Dya*_*ana的帖子

将swifty json数组保存到用户默认值

我有一个json data,它提供以下信息:

let data = [
  {
    "QuestionTitle" : "Entomology is the science that studies",
    "Id" : 205,
    "Options" : [
      { "Option" : "Insects", "Id" : 810 },
      { "Option" : "The origin and history of technical and scientific terms", "Id" : 811 },
      { "Option" : "The formation of rocks", "Id" : 812 },
      { "Option" : "Behavior of human beings", "Id" : 809 }
    ]
  },
  {
    "QuestionTitle" : "A train running at the speed of …
Run Code Online (Sandbox Code Playgroud)

swift alamofire swifty-json

5
推荐指数
1
解决办法
2524
查看次数

快速比较字典值

我有一系列类型的字典

[["OptionId": 824, "QuestionId": 208],
["OptionId": 810, "QuestionId": 205],
["OptionId": 1017, "QuestionId": 257],
["OptionId": 0, "QuestionId": 201],
["OptionId": 0, "QuestionId": 199],
["OptionId": 0, "QuestionId": 200]]
Run Code Online (Sandbox Code Playgroud)

我迭代了这些值并将字典值提取为

["OptionId": 824, "QuestionId": 208]
["OptionId": 810, "QuestionId": 205]
["OptionId": 1017, "QuestionId": 257]
["OptionId": 0, "QuestionId": 201]
["OptionId": 0, "QuestionId": 199]
["OptionId": 0, "QuestionId": 200]
Run Code Online (Sandbox Code Playgroud)

现在,我想获取所有为 0 的“OptionId”的“QuestionId”。如何将字典键值与零进行比较?提前致谢。

这是我到目前为止所尝试过的:

for dictionary in arrayofDict {
    print(dictionary)
    if (dictionary["OptionId"] == 0) {
        print("option not selected")
    }
} 
Run Code Online (Sandbox Code Playgroud)

arrays dictionary ios swift

3
推荐指数
1
解决办法
2732
查看次数

检查在字典swift 3数组中是否存在值

我有一个称为字典的数组,arrayOfDict其中包含许多都具有相同键的字典对象:QUESTIONIDOPTIONID

[ //arrayOfDict
   {QUESTIONID:1, OPTIONID:0},
   {QUESTIONID:2, OPTIONID:201},
   {QUESTIONID:3, OPTIONID:204)
 ];
Run Code Online (Sandbox Code Playgroud)

arrayOfDict仅当我要添加的字典不包含此类字典时,才需要添加此类字典QUESTIONID。如果QUESTIONID已经存在,则OPTIONID需要用新的替换。如何QUESTIONIDQUESTIONIDin 比较arrayOfDict

swift

3
推荐指数
1
解决办法
2278
查看次数

标签 统计

swift ×3

alamofire ×1

arrays ×1

dictionary ×1

ios ×1

swifty-json ×1