shrimp-hamburger 2013-04-03 06:05 采纳率: 0%
浏览 4815

实体类到另一个实体类传递数据

在chapterDC类中有一个selectedRegion,其中的区域数据需要传递到 regionDC。通过chapterDC来传递。chapterDC中有区域。

但是返回的结果不是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;
}
  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2022-12-20 17:17
    关注

    ChatGPT尝试为您解答,仅供参考
    这段代码看起来像是从一个web service接口获取数据并解析成ChapterDC对象的数组。其中ChapterDC有一个RegionDC属性selectedRegion。

    看起来你的问题是selectedRegion的RegionDC_RegionID总是返回0或者null。


    为了找出问题的原因,我建议你检查一下以下几点:

    • 确保web service接口在返回数据时包含了RegionID和RegionName字段。可以在调用接口之后打印出responseDict和regionDict的内容来检查。

    • 确保你在解析responseDict和regionDict时使用的键名是正确的。比如说,如果在返回的数据中RegionID的键名是"region_id"而不是"RegionID",那么你就会得到0或null的值。

    • 确保你在解析responseDict和regionDict时使用的类型是正确的。比如说,如果在返回的数据中RegionID的类型是字符串而不是整数,那么你就会得到0或null的值。

    • 确保你在调用getAllChapters方法时正确地调用了callWebService方法。

    希望这些建议能帮助你解决问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题