当我打印(JSON)时,我得到了文件,所以.request有效。 但是当我尝试访问“test” key (存在)时,我得到 nil
我明白
"I am here"
"now ,I am here"
Alamofire.request(.GET, self.APIBaseUrl , parameters: ["api_key": self.APIkey])
.responseJSON { response in
if let JSON = response.result.value {
print("I am here")
if let str = JSON as? NSDictionary {
print("now , I am here")
if let movieUrlString = str["poster_path"] as? String)! {
print("but now here")
}
已编辑
print(dict)
**dates** = {
maximum = "2015-10-21";
minimum = "2015-09-30";
};
page = 1;
**results** = (
{
adult = 0;
"poster_path" = "/2XegKZ0I4QrvzpEHneigRk6YTB1.jpg";
++(更多结果)
最佳答案
尝试使用更有意义的调试打印语句和变量名称。此外,您没有使用正确的变量进行下标。固定示例:
Alamofire.request(.GET, self.APIBaseUrl , parameters: ["api_key": self.APIkey]).responseJSON { response in
if let JSON = response.result.value {
print("inside JSON result")
if let dict = JSON as? NSDictionary {
print("inside decoded JSON")
if let results = dict["results"] as? [NSDictionary] {
for result in results {
if let movieUrlString = result["poster_path"] as? String {
print(movieUrlString)
}
}
}
}
}
}
关于json - Swift:访问 NSDictionairy 时 JSON 为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32822436/