简体   繁体   English

“ [__NSDictionaryI内容]:无法识别的选择器已发送到实例”从Custom JsonModel获取数据时

[英]“[__NSDictionaryI content]: unrecognized selector sent to instance” When getting data from Custom JsonModel

I have implemented following JsonModels. 我已经实现了以下JsonModels。

@interface MainModel : JSONModel
    @property (nonatomic) NSArray<CCLSecurityChecklistModel *> *cclSecurityChecklist;
@end

@interface CCLSecurityChecklistModel : JSONModel
    @property (nonatomic) NSString *section;
    @property (nonatomic) NSString *location;
    @property (nonatomic) NSString *nfc;
    @property (nonatomic) NSArray <ContentModel *> *content;
@end

@interface ContentModel : JSONModel
    @property (nonatomic) NSString *question;
    @property (nonatomic) NSString *type;
    @property (nonatomic) NSString *required;
    @property (nonatomic) NSString *extra;
    @property (nonatomic) NSArray *choices;
    @property (strong, nonatomic) AnswerModel *answer;
@end

Here is my Json. 这是我的杰森。

{"cclSecurityChecklist" :[
                      {
                      "section": "Security Checklist - CTSG (1)",
                      "location": "",
                      "nfc": true,
                      "content": [
                                  {
                                    "question": "",
                                    "type": "checkbox",
                                    "required": true,
                                    "extra": true,
                                    "choices": ["Exits/ Entrances", "Air in-take shafts", "Bicycle Parking Area", "Dustbin area near entrance", "Subway Area",
                                                "Concourse", "Lifts", "Non-lockable compartments along passage way (both paid & unpaid areas)", "Fire equipment cabinets",
                                                "Emergency Exits", "Doors leading to controlled area/non-public area are locked", "Staircase landings", "Platforms",
                                                "End of platforms", "Seating area"],
                                    "answer": {
                                      "value": [],
                                      "photos": [],
                                      "remarks": []
                                    }
                                  }
                                  ]
                      },
                      {
                      "section": "Security Checklist - CTSG (2)",
                      "location": "Concourse - public area",
                      "nfc": true,
                      "content": [
                                  {
                                    "question": "",
                                    "type": "checkbox",
                                    "required": true,
                                    "extra": true,
                                    "choices": ["AED - a)Housing Cabinet in good condition. b)Signage is intact and displayed. c) glass piece for key pocket is not broken.d) key is present. e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking"],
                                    "answer": {
                                      "value": [],
                                      "photos": [],
                                      "remarks": []
                                    }
                                  }
                                  ]
                      }
                      ]
}

Here is how I convert JsonString to MainModel in AppDelegate. 这是我在AppDelegate中将JsonString转换为MainModel的方法。

- (NSArray<CCLSecurityChecklistModel *> *)convertJsonToModel:(NSString *)fileName{
    NSError *error;

    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSString * myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    MainModel *model= [[MainModel alloc] initWithString:myString error:&error];
    return model.cclSecurityChecklist;
}

This is the result when I print out the MainModel. 这是我打印MainModel时的结果。

 <MainModel> 
   [cclSecurityChecklist]: (
           {
           content =         (
                           {
                   answer =                 {
                       photos =                     (
                       );
                       remarks =                     (
                       );
                       value =                     (
                       );
                   };
                   choices =                 (
                       "Exits/ Entrances",
                       "Air in-take shafts",
                       "Bicycle Parking Area",
                       "Dustbin area near entrance",
                       "Subway Area",
                       Concourse,
                       Lifts,
                       "Non-lockable compartments along passage way (both paid & unpaid areas)",
                       "Fire equipment cabinets",
                       "Emergency Exits",
                       "Doors leading to controlled area/non-public area are locked",
                       "Staircase landings",
                       Platforms,
                       "End of platforms",
                       "Seating area"
                   );
                   extra = 1;
                   question = "";
                   required = 1;
                   type = checkbox;
               }
           );
           location = "";
           nfc = 1;
           section = "Security Checklist - CTSG (1)";
       },
           {
           content =         (
                           {
                   answer =                 {
                       photos =                     (
                       );
                       remarks =                     (
                       );
                       value =                     (
                       );
                   };
                   choices =                 (
                       "AED - a)Housing Cabinet in good condition. b)Signage is intact and displayed. c) glass piece for key pocket is not broken.d) key is present. e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking"
                   );
                   extra = 1;
                   question = "";
                   required = 1;
                   type = checkbox;
               }
           );
           location = "Concourse - public area";
           nfc = 1;
           section = "Security Checklist - CTSG (2)";
       }
       )
    </MainModel>

Here is retrieving data from JsonModel's Object in other ViewController. 这是从其他ViewController中的JsonModel的Object检索数据。 在此处输入图片说明

But I got this error when I retrieving content from CCLSecurityChecklistModel's object. 但是,当我从CCLSecurityChecklistModel的对象检索内容时,出现了此错误。

-[__NSDictionaryI content]: unrecognized selector sent to instance 0x6000000f3280

This my very first time of using JsonModel Mapper. 这是我第一次使用JsonModel Mapper。 Can anyone suggest me and help me for this issue. 谁能建议我并帮助我解决这个问题。 I was stuck here. 我被困在这里。 Sorry for long explanations. 很抱歉,冗长的解释。

Luckily I found the solution based on the hints from the above answers. 幸运的是,我根据以上答案的提示找到了解决方案。 I changed the Json format to this 我将Json格式更改为此

[
{
    "section": "Security Checklist - CTSG (1)",
    "location": "",
    "nfc": true,
    "content": [
                {
                "question": "",
                "type": "checkbox",
                "required": true,
                "extra": true,
                "choices": ["Exits/ Entrances", "Air in-take shafts", "Bicycle Parking Area", "Dustbin area near entrance", "Subway Area",
                            "Concourse", "Lifts", "Non-lockable compartments along passage way (both paid & unpaid areas)", "Fire equipment cabinets",
                            "Emergency Exits", "Doors leading to controlled area/non-public area are locked", "Staircase landings", "Platforms",
                            "End of platforms", "Seating area"],
                "answer": {
                "value": [],
                "photos": [],
                "remarks": []
                }
                }
                ]
},
{
    "section": "Security Checklist - CTSG (2)",
    "location": "Concourse - public area",
    "nfc": true,
    "content": [
                {
                "question": "",
                "type": "checkbox",
                "required": true,
                "extra": true,
                "choices": ["AED - a)Housing Cabinet in good condition. b)Signage is intact and displayed. c) glass piece for key pocket is not broken.d) key is present. e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking.e) Green light indication on the AED is blinking"],
                "answer": {
                "value": [],
                "photos": [],
                "remarks": []
                }
                }
                ]
}
]

and Changed the code for Converting Json to Model into this. 并更改了将Json转换为Model的代码。

    - (NSArray<CCLSecurityChecklistModel *> *)convertJsonToModel:(NSString *)fileName{
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSString * myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSMutableArray *yourArray = [CCLSecurityChecklistModel arrayOfModelsFromString:myString error:nil];
    MainModel *objCardData = [[MainModel alloc] init];
    objCardData.cclSecurityChecklist = yourArray;

    return objCardData.cclSecurityChecklist;
}

according to this answer. 根据这个答案。 parse json using JsonModel 使用JsonModel解析json

Thanks so much all for your time. 非常感谢您的宝贵时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [__NSDictionaryI个字节]:无法识别的选择器已发送到实例 - [__NSDictionaryI bytes]: unrecognized selector sent to instance [__NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例 - [__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance [NSDictionaryI setObject:forKey:]: 无法识别的选择器发送到实例 - [NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance -[__ NSDictionaryI arrayForKey:]:无法识别的选择器已发送到实例 - -[__NSDictionaryI arrayForKey:]: unrecognized selector sent to instance -[__ NSDictionaryI rangeOfString:options:]:无法识别的选择器已发送到实例 - -[__NSDictionaryI rangeOfString:options:]: unrecognized selector sent to instance &#39; - [__ NSDictionaryI length]:无法识别的选择器发送到实例&#39; - 试图找出原因 - '-[__NSDictionaryI length]: unrecognized selector sent to instance' - trying to figure out why -[__ NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例0x91da0f0 - -[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x91da0f0 尝试使用TWRequest发布时获取“无法识别的选择器发送到实例” - Getting “unrecognized selector sent to instance” when trying to post with TWRequest 使用核心数据和快速获取错误“无法识别的选择器发送到实例” - Getting the error “unrecognized selector sent to instance” with core data and swift 使用自定义表格单元格时,“无法识别的选择器已发送到实例” - “Unrecognized selector sent to instance” when using custom table cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM