http传参json格式

http需要传一个类似于这样的参数 : 

list=[{"id":"R000009A5A5A5AD3606","ch":"R000009A5A5A5AD3606_1894”},{"id":"R000009A5A5A5AD3609","ch":"R000009A5A5A5AD3607_189"}]


弄了好久没弄出来,原来直接用下面的方法就可以




NSArray *array = [self getBookShelfList];

        

        NSMutableArray *listArray = [[NSMutableArray alloc] init];

        

        for (int i = 0; i < array.count; i++) {

            

            BDStoryBookDetailInfo *bookInfo = array[i];

            

            [listArray addObject:@{@"id":bookInfo.bookID,@"ch":[bookInfo getLastChapterID]}];

            

        }

        

        NSData *listData = [NSJSONSerialization dataWithJSONObject:listArray options:0 error:nil];

        NSString *listJSON = [[NSString alloc] initWithData:listData encoding:NSUTF8StringEncoding];

        

        

        NSString *updateListURL = [BDStoryBrokerManager fetchStoryBookUpdateUrlString];

        //

        [[BDStoryNetwork sharedInstance] startNetwork:updateListURL parameter:@{@"list":listJSON} withHttpMethod:@"POST" successCompletionHandler:^(MKNetworkOperation *task) {





说明的是下面的这种方法不知道为什么也不可以:

        NSDictionary *beforeDic = [NSDictionary dictionaryWithObjectsAndKeys:@"R000009A5A5A5AD3606",@"id",@"R000009A5A5A5AD3606_1894",@"ch", nil];

        NSArray *arrayRep = [NSArray arrayWithObjects:beforeDic, nil];

        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:arrayRep,@"list", nil];

        

        

        [[BDStoryNetwork sharedInstance] startNetwork:updateListURL parameter:dict withHttpMethod:@"POST" successCompletionHandler:^(MKNetworkOperation *task) {


你可能感兴趣的:(http传参json格式)