1. 程式人生 > >ios 巢狀json解析

ios 巢狀json解析

{"success":true,"code":"2001","message":"查詢成功","data":[{"userListByPreWeekHitTimes":[{"UserId":207677921948,"NickName":"站點管理員","Avatar":"http://192.168.1.103:8066/Uploads/Avatars/avatar_default.jpg","BigAvatar":"http://192.168.1.103:8066/Uploads/Avatars/avatar_default_big.jpg","Gender":0,"NowAreaCode":"","IsFollowed":false,"FollowerCount":0,"FollowedCount":0}],"userListByOnline":[],"userListByInterested":null}]}

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];

// 原本需要拼接get訪問URL ? & =

// NSDictionary *dict = @{@"format": @"json"};

// 網路訪問是非同步的,回撥是主執行緒的,因此程式設計師不用管在主執行緒更新UI的事情

    [manager GET:@"http://192.168.1.103:8066/MobileClient_2/UserSpace/UserList.aspx"parameters:nilsuccess:^(

AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@"%@", responseObject);

// 提問:NSURLConnection非同步方法回撥,是在子執行緒

// 得到回撥之後,通常更新UI,是在主執行緒

NSLog(@"%@", [NSThreadcurrentThread]);

NSMutableArray* dic1=[responseObject objectForKey:@"data"];

NSMutableDictionary* dic2=[dic1 objectAtIndex:0];

NSMutableArray

* dic3=[dic2 objectForKey:@"userListByPreWeekHitTimes"];

NSMutableDictionary* dic4=[dic3 objectAtIndex:0];

NSString* str=[dic4 objectForKey:@"NickName"];

//解析json到各個字串

NSLog(@".......%@",str);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

NSLog(@"%@", error);

    }];

【】代表陣列 用array {}代表dic 用dictionary做。。。。不熟悉容器啊