IOS JSON

//請求數據
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        _dataArray=[NSMutableArray array];
        NSString *urlStr=[NSString stringWithFormat:MAINMENU_URL,kHost_And_Port];
        NSLog(@"%@", urlStr);
        NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
        if (data) {
            NSDictionary *rootdict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            for (NSDictionary *dic in rootdict[@"data"]) {
                [_dataArray addObject:dic[@"imagePathLandscape"]];
            }
            //回到主線程  刷新數據
            dispatch_async(dispatch_get_main_queue(), ^{
                [_tableView reloadData];
            });
        }
    });
相關文章
相關標籤/搜索