V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
GhostEX
V2EX  ›  问与答

这段代码能用 OC 写出来么 在线求大神...

  •  
  •   GhostEX · 2015-12-31 11:03:57 +08:00 · 2326 次点击
    这是一个创建于 3060 天前的主题,其中的信息可能已经有所发展或是发生改变。
    23 条回复    2015-12-31 16:42:58 +08:00
    babyhome
        1
    babyhome  
       2015-12-31 11:13:18 +08:00
    任何语言都可以写出来啊。。。
    morefreeze
        2
    morefreeze  
       2015-12-31 11:26:40 +08:00
    LMkillme
        3
    LMkillme  
       2015-12-31 11:29:11 +08:00
    @babyhome
    @morefreeze
    楼主问的不是 OC 能不能写出来,是问你们能不能用 OC 把这段代码写下来?
    morefreeze
        4
    morefreeze  
       2015-12-31 11:38:01 +08:00
    felixzhu
        5
    felixzhu  
       2015-12-31 11:49:48 +08:00
    没有对齐看得我好难受。。
    GhostEX
        6
    GhostEX  
    OP
       2015-12-31 11:49:57 +08:00
    @morefreeze 我不信:-D
    Reficul
        7
    Reficul  
       2015-12-31 12:54:27 +08:00
    诶,不会 OC 的表示,这段有啥特别的以至于 OC 不能写?
    GhostEX
        8
    GhostEX  
    OP
       2015-12-31 12:57:49 +08:00
    @Reficul 是我不懂 java ,希望有人能写下 oc 版
    SourceMan
        9
    SourceMan  
       2015-12-31 13:02:38 +08:00
    楼主希望答案是写出来,不是能不能
    sandideas
        10
    sandideas  
       2015-12-31 13:03:07 +08:00 via iPhone
    这就是一个简单的链接吧?
    em70
        11
    em70  
       2015-12-31 13:03:56 +08:00
    伸手党
    Elethom
        12
    Elethom  
       2015-12-31 13:04:12 +08:00
    這種問題需要置頂嗎。請不要濫用置頂功能。

    答案:能。
    unique
        13
    unique  
       2015-12-31 13:08:30 +08:00
    - -!
    wohenyingyu01
        14
    wohenyingyu01  
       2015-12-31 13:39:21 +08:00
    能啊
    lululau
        15
    lululau  
       2015-12-31 13:43:50 +08:00
    没有 close/release 真的不要紧吗
    Kilerd
        16
    Kilerd  
       2015-12-31 14:13:58 +08:00
    伸手党!能写都拒绝!
    wbsdty331
        17
    wbsdty331  
       2015-12-31 14:23:07 +08:00
    @Elethom 估计是铜币多的慌吧
    zzmstring
        18
    zzmstring  
       2015-12-31 16:01:53 +08:00 via Android
    。。。
    KylinRoc
        19
    KylinRoc  
       2015-12-31 16:05:23 +08:00
    @Elethom 一小段时间里密集回复也会被置顶的
    morefreeze
        20
    morefreeze  
       2015-12-31 16:10:44 +08:00
    @GhostEX 好吧 你摸牌吧
    LINAICAI
        21
    LINAICAI  
       2015-12-31 16:39:51 +08:00   ❤️ 1
    BOOL b;
    @try {
    NSURL *url=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    request.timeoutInterval=30;
    [request setHTTPMethod:@"GET"];
    NSHTTPURLResponse *response=nil;
    NSError *error=nil;
    NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSInteger a= [response statusCode];
    NSLog(@"ResponseState=%ld",a);
    if (a!=200 || error) {
    NSLog(@"Exception=%@",@"网络错误异常!!!!");
    b = NO;
    }
    else{
    //json 解析
    id json=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
    NSLog(@"请求返回的 json 数据为%@",json);
    //TO DO
    //得到 json
    b = YES;

    }
    }
    @catch (NSException *exception) {
    NSLog(@"调用堆栈=%@",exception.callStackSymbols);
    NSLog(@"Exception=%@",@"这是异常!");
    NSLog(@"Exception=%@",exception.description);
    b = NO;


    }
    @finally {
    return b;
    }
    GhostEX
        22
    GhostEX  
    OP
       2015-12-31 16:41:16 +08:00
    @LINAICAI 谢谢大神。
    LINAICAI
        23
    LINAICAI  
       2015-12-31 16:42:58 +08:00
    说实在的如果 OC 按照楼主你这样写感觉很别扭
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2262 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:23 · PVG 09:23 · LAX 18:23 · JFK 21:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.