• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 如何用字符串数组中的 %20 填充空字符串 ios

[复制链接]
菜鸟教程小白 发表于 2022-12-13 03:19:01 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个从 JSON 对象中找到的字符串数组。目前是一个包含 4 张图像的图像数组。我不知道将来会得到多少张图像。 我的问题是图像 URL 没有显示在我的 ImageView 中,因为它包含一些空白空间。我已经检查了这个空间是否被替换为 %20,然后我可以在我的 ImageView 中愉快地使用它。

谁能建议我如何替换此图像数组中所有图像字符串 URL 中的所有空格?

请找到我的相同代码:-----

    NSArray* latest = [json objectForKey"BANNER"];

    NSMutableArray *data=[NSMutableArray new];

      if (!latest) {

        NSLog(@"Error parsing JSON: %@",error);
    }
       else{

        for(int i=0; i<latest.count ; i++)
        {
            NSDictionary *dict = [latest objectAtIndex:i];

            [data addObject:[dict objectForKey"url"]];
        }
        NSLog(@"data :%@",data);
        }

# Pragma Mark: 我找到了以下格式的图像数组

data 
    "https://xyz.in/mobile/1508139616-Food Offer Banner App (1).jpg",
    "https://xyz.in/mobile/1508163055-Serving  Banner app.jpg",
    "https://xyz.in/mobile/1508746128-Food App Banner Deal10.jpg",
    "https://xyz.in/mobile/1508746172-Food Banner Features.jpg"
)

Pragma Mark:我想像这样转换“数据”

data 
    "https://xyz.in/mobile/1508139616-Food%20Offer%20Banner%20App%20(1).jpg",
    "https://xyz.in/mobile/1508163055-Serving%20Banne%20app.jpg",
    "https://xyz.in/mobile/1508746128-Food%20App%20Banner%20Deal10.jpg",
    "https://xyz.in/mobile/1508746172-Food%20Banner%20Features.jpg"
)

我知道这个问题已经存在,但仅针对单个字符串。但我的问题是我想转换完整的字符串 URL 数组。 请帮助我已经用了 3-4 天。



Best Answer-推荐答案


让我们使用 stringByReplacingOccurrencesOfString。它可以帮助你用 %20 替换所有空格。

yourImageUrlString = [yourImageUrlString stringByReplacingOccurrencesOfString" " withString"%20"];

为您的代码

NSArray* latest = [json objectForKey"BANNER"];

NSMutableArray *data=[NSMutableArray new];

if (!latest) {

  NSLog(@"Error parsing JSON: %@",error);
}
else{

  for(int i=0; i<latest.count ; i++)
  {
    NSDictionary *dict = [latest objectAtIndex:i];
    NSString *url = [dict objectForKey"url"];
    url = [url stringByReplacingOccurrencesOfString" " withString"%20"];
    [data addObject:url];
  }
  NSLog(@"data :%@",data);
}

关于ios - 如何用字符串数组中的 %20 填充空字符串 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47345014/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap