我正在尝试从NSDictionary解析数据,但是遇到了麻烦。每当我尝试访问此信息时,它都会显示nil。
NSDictionary:
{
"-LTR7P8PFWHogjlBENiJ" = {
filmid = 335983;
rating = "5.5";
review = Ehh;
};
}
代码:
let dict = info.value as! NSDictionary
print(dict) //prints about NSDict
print(dict["review"] as? String) //prints nil
从NSDictionary打印“ Ehh”的正确方法是什么?
答案 0 :(得分:2)
您具有搜索结果的外部字典包装,带有字符串键-LTR7P8PFWHogjlBENiJ
因此,您的代码当前正在外部字典中搜索键review
。
答案 1 :(得分:1)
您可以如下获得Unable to import module 'src/engine/handler': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous>(/var/task/src/engine/controllers/image.js:43:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
值,
review
对于typealias JSON = [String: Any]
let dictionary: JSON = [
"-LTR7P8PFWHogjlBENiJ": [
"filmid": 335983,
"rating": "5.5",
"review": "Ehh"
]
]
if let reivew = (dictionary.first?.value as? JSON)?["review"] as? String {
print(reivew)
}
,您可能需要如下使用
NSDictionary