zoukankan      html  css  js  c++  java
  • 源码0602-05-掌握-多值参数

    //
    //  ViewController.m
    //  05-掌握-多值参数
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        // 0.请求路径
        NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/weather?place=Beijing&place=Shanghai"];
        
        // 1.创建请求对象
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
        // 2.发送请求
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSLog(@"
    %@", [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]);
        }];
    }
    
    @end
    //
    //  NSDictionary+Log.m
    //  05-掌握-多值参数
    #import <Foundation/Foundation.h>
    
    @implementation NSDictionary (Log)
    - (NSString *)descriptionWithLocale:(id)locale
    {
        NSMutableString *string = [NSMutableString string];
        
        // 开头有个{
        [string appendString:@"{
    "];
        
        // 遍历所有的键值对
        [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
            [string appendFormat:@"	%@", key];
            [string appendString:@" : "];
            [string appendFormat:@"%@,
    ", obj];
        }];
        
        // 结尾有个}
        [string appendString:@"}"];
        
        // 查找最后一个逗号
        NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
        if (range.location != NSNotFound)
        [string deleteCharactersInRange:range];
        
        return string;
    }
    @end
    
    @implementation NSArray (Log)
    
    - (NSString *)descriptionWithLocale:(id)locale
    {
        NSMutableString *string = [NSMutableString string];
        
        // 开头有个[
        [string appendString:@"[
    "];
        
        // 遍历所有的元素
        [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            [string appendFormat:@"	%@,
    ", obj];
        }];
        
        // 结尾有个]
        [string appendString:@"]"];
        
        // 查找最后一个逗号
        NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
        if (range.location != NSNotFound)
        [string deleteCharactersInRange:range];
        
        return string;
    }
    
    @end
    本人无商业用途,仅仅是学习做个笔记,特别鸣谢小马哥,学习了IOS,另日语学习内容有需要文本和音频请关注公众号:riyuxuexishuji
  • 相关阅读:
    android学习日记19--四大组件之BroadcastReciver(广播接收者)
    android学习日记19--四大组件之Services(服务)
    android学习日记18--Adapter简介
    android学习日记17--Gallery(画廊视图)
    android学习日记16--GridView(网格视图)
    android学习日记15--WebView(网络视图)
    android学习日记14--网络通信
    android报错及解决2--Sdcard进行文件的读写操作报的异常
    android学习日记13--数据存储之File存储
    自定义跨浏览器的事件处理程序
  • 原文地址:https://www.cnblogs.com/laugh/p/6595966.html
Copyright © 2011-2022 走看看