iOS中NSURL常用属性

 

    NSString *urlstr = @"http://api.test.com:8080/test/index.php?g=api&m=base&a=skyuv&city=110229";
    NSURL *url = [NSURL URLWithString:urlstr];
    NSLog(@"scheme:%@", url.scheme);                    //协议 http
    NSLog(@"host:%@", url.host);                        //域名 api.test.com
    NSLog(@"port:%@", url.port);                        //端口 8080
    NSLog(@"absoluteString:%@", url.absoluteString);    //完整的url字符串
    NSLog(@"relativePath: %@", url.relativePath);       //相对路径 /test/index.php
    NSLog(@"path: %@", url.path);                       //路径 /test/index.php
    NSLog(@"pathComponents:%@", url.pathComponents);    //("/",test,"index.php")
    NSLog(@"Query:%@", url.query);                      //参数 g=api&m=base&a=skyuv&city=110229

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Java的BufferedImage对象放入Map返回给iOS端,可以使用以下步骤: 1. 创建一个Map对象,并将BufferedImage对象放入其。 2. 将Map对象转换为JSON格式的字符串。 3. 使用HTTP协议将JSON字符串发送到iOS端。 4. 在iOS端接收HTTP响应的JSON字符串,将其解析为NSDictionary对象,并从获取BufferedImage对象。 以下是一个简单的示例代码: Java端: ``` // 读取图片并转换为BufferedImage对象 BufferedImage image = ImageIO.read(new File("path/to/image.jpg")); // 创建一个Map对象,并将BufferedImage对象放入其 Map<String, Object> map = new HashMap<>(); map.put("image", image); // 将Map对象转换为JSON格式的字符串 ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(map); // 将JSON字符串返回给客户端 return jsonString; ``` iOS端: ``` NSURL *url = [NSURL URLWithString:@"http://your-java-server.com/get-image"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if (data) { // 解析JSON字符串为NSDictionary对象 NSError *error = nil; NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; // 从NSDictionary对象获取BufferedImage对象 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:jsonDict[@"image"] options:NSDataBase64DecodingIgnoreUnknownCharacters]; UIImage *image = [UIImage imageWithData:imageData]; // 在这里使用UIImage对象 } else { NSLog(@"%@", error); } }]; ``` 注意:在实际开发,要考虑到JSON序列化和反序列化的效率,以及图片大小、网络传输速度等因素,以保证图片的快速加载和显示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值