gpt4 book ai didi

ios - 在将其解析为 JSON 文件 Swift 后声明类型

转载 作者:行者123 更新时间:2023-11-29 01:05:02 25 4
gpt4 key购买 nike

现在我有一个从 Pearson 的 API 获得的 JSON 输出:

Optional(<__NSCFArray 0x7f9b7601a910>(
{
datasets = (
laad3,
dictionary
);
headword = theoretically;
id = cs1tNTvYvg;
"part_of_speech" = adverb;
senses = (
{
definition = "used to say that something could happen, but it is extremely unlikely";
examples = (
{
text = "It\U2019s theoretically possible for everyone in the class to get 100%.";
}
);
}
);
url = "/v2/dictionaries/entries/cs1tNTvYvg";
},
{
datasets = (
laad3,
dictionary
);
headword = theoretical;
id = cs1tNTpDbZ;
"part_of_speech" = adjective;
senses = (
{
definition = "relating to or based on ideas, especially scientific ideas, rather than practical work or experience";
examples = (
{
text = "theoretical research";
}
);
}
);
url = "/v2/dictionaries/entries/cs1tNTpDbZ";
})

并假设上面的输出存储到:

let results = parsedResult!["results"]

XCode 说下标的使用不明确,谷歌搜索后似乎我必须转换结果类型才能继续。我必须将 results 的类型转换为例如[[String:String]]?

旁注:有谁知道为什么 Xcode 提示在我的 iPhone6 和 iOS 9.3 上选择运行目标时下标使用不明确,但在模拟器中运行时却没有(也在 iPhone6 和 iOS9.3 上) ?

最佳答案

我不明白这个问题的深层原因。但从 XCode 7.3(或者更确切地说是 Swift 2.2)开始,编译器现在会在使用 NSDictionary 时提示下标的使用不明确

要避免该错误,请将 NSDictionary 实例转换为 [String: AnyObject] 并将 NSArray 实例转换为 [AnyObject].

关于ios - 在将其解析为 JSON 文件 Swift 后声明类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36518413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com