本文介绍了当“< null">发生崩溃时因为在SWIFT中收到了来自api的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从api获取图像URL null作为响应,有什么方法可以修复它.api的响应是:
Getting the image url null as response from api, is there any way for fix it. Response from api is:
"image_path" = "<null>";
试图这样处理:
if !(arrList.objectAtIndex(indexPath.row).valueForKey("media")?.objectAtIndex(0).valueForKey("image_path") is NSNull) {
// optional is NOT NULL, neither NIL nor NSNull
}
它仍然崩溃,请指导.更新:
It is still crashing please guide.Update:
发现了问题,null实际上不是问题.在下面发布回复,以使事情变得清楚.
Found the problem, null was not the issue actually. Posting the response below to make things clear.
media = (
{
id = "97eb48a0-429a-11e6-873c-ad7b848648f1";
"image_path" = "https://s3-eu-west-1.mazws.com/facebook_profile_images/15105131.png";
"room_post_id" = "97c572e0-429a-11e6-b72b-fd489f63a1fc";
"user_id" = "66fe22a0-4296-11e6-a1d9-69dc307add4b";
"video_path" = "<null>";
},
{
id = "981a6880-429a-11e6-b039-736a0bf954dc";
"image_path" = "<null>";
"room_post_id" = "97c572e0-429a-11e6-b72b-fd489f63a1fc";
"user_id" = "66fe22a0-4296-11e6-a1d9-69dc307add4b";
"video_path" = "https://s3-eu-west-1.naws.com/facebook_profile_images/1255803.mp4";
}
);
这是正常的响应,现在是麻烦所在的响应:
This is the normal response, now the response where trouble is:
media = (
);
该如何处理?请指导.
推荐答案
像这样尝试..它不会崩溃
Try like this .. it'll not crash
if let imgPath = arrList.objectAtIndex(indexPath.row).valueForKey("media")?.objectAtIndex(0).valueForKey("image_path") as? String {
//... your value is string
}
这篇关于当“< null">发生崩溃时因为在SWIFT中收到了来自api的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!