iphone - 如何将数据从一个实体传递到另一个实体类?

标签 iphone ios json web-services

我正在获取 chapterDC 类中的所有章节并获取区域,我在 chapterDC 类中有一个 selectedRegion 属性,想通过 chapterDC 将我的区域数据传递到 regionDC,但我的日志消息始终为 0 和 null,我不知道我在做什么错误

-(NSMutableArray *)getAllChapters
{
    NSMutableArray *returnArray = [[NSMutableArray alloc] init];

    NSString *url = [NSString stringWithFormat:@"%@get_all_chapters",kWSURL];
    NSDictionary * returnDict = (NSDictionary *) [self callWebService:url];
    if([[returnDict objectForKey:@"status"] isEqualToString:@"success"])
    {
        NSDictionary * responseDict = (NSDictionary *) [returnDict objectForKey:@"response"];
        NSArray *resultArray = [responseDict objectForKey:@"result"];

        for(NSDictionary *chapterDict in resultArray)
        {
            ChapterDC * chapter = [[ChapterDC alloc] init];
            chapter.ChapterDC_ChapterID=[[chapterDict objectForKey:@"ChapterID"]intValue];
            chapter.ChapterDC_ChapterName = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"ChapterName"]];
            chapter.selectedRegion.RegionDC_RegionID=[ [chapterDict objectForKey:@"RegionID"]intValue];
             NSLog(@"%d",chapter.selectedRegion.RegionDC_RegionID);
            chapter.ChapterDC_AddressLine1 = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"AddressLine1"]];
            chapter.ChapterDC_AddressLine2 = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"AddressLine2"]];
            chapter.ChapterDC_AddressLine3 = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"AddressLine3"]];
            chapter.ChapterDC_Email = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"Email"]];
            chapter.ChapterDC_URL = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"URL"]];
            chapter.ChapterDC_FacebookURL =[ NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"FacebookURL"]];
            chapter.ChapterDC_LinkedInURL = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"LinkedInURL"]];
            chapter.ChapterDC_PhoneNumber =[ NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"PhoneNumber"]];
            chapter.ChapterDC_Postcode = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"Postcode"]];
            chapter.ChapterDC_TwitterURL = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"TwitterURL"]];

            NSDictionary * regionDict = (NSDictionary *) [returnDict objectForKey:@"region"];

            {
            chapter.selectedRegion = [[RegionDC alloc] init];
            chapter.selectedRegion.RegionDC_RegionID = [[regionDict objectForKey:@"RegionID"]intValue];
            NSLog(@"%d",chapter.selectedRegion.RegionDC_RegionID);
            chapter.selectedRegion.RegionDC_RegionName = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"RegionName"]];
                NSLog(@"%@",chapter.selectedRegion.RegionDC_RegionName);
            chapter.selectedRegion.RegionDC_ContactName = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"ContactName"]];
            chapter.selectedRegion.RegionDC_Mobile = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"Mobile"]];
            chapter.selectedRegion.RegionDC_Landline = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"Landline"]];
            chapter.selectedRegion.RegionDC_TrainingURL = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"TrainingURL"]];
            }
            [returnArray addObject:chapter];
        }
    }
    return returnArray;
}

最佳答案

替换 NSDictionary * regionDict = (NSDictionary *) [returnDict objectForKey:@"region"];

NSDictionary * regionDict = (NSDictionary *) [chapterDict objectForKey:@"region"];

关于iphone - 如何将数据从一个实体传递到另一个实体类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15739066/

相关文章:

iphone - #import <libxml/HTMLparser.h> 要导入什么库

iPhone UIPickerView 手势

iphone - 我怎么知道我有什么设备?

ios - 在 Xcode 中,您将如何拥有只有在用户在应用程序中执行特定操作时才能访问的 View Controller ?

javascript - "undefined is not a function"onSuccessHandler

ios - 更改 UIImageView 中 UIImage 的大小和位置(快速)

ios - 检测 TableView 中 UIGestureRecognizer 的来源单元

IOS/objective-C : Fastest way to check for Internet connection - 2017

javascript - 根据嵌套值按字典顺​​序对对象数组进行排序

c# - 在 JSON.NET 中反序列化此对象