0

How can i map this json

{
  "json": [{
    "json_department": [{
      "department": {
        "id": 1,
        "inst_id": 1,
        "dept_name": "Department",
        "description": "test"
      },
      "needDelete": true
    }],
    "json_subjects": [{
      "subjects": [{
        "id": 1,
        "department_id": 1,
        "subject_name": "Sub 1"
      }, {
        "id": 2,
        "department_id": 1,
        "subject_name": "Sub 2"
      }],
      "needDelete": true
    }]
  }]
}
@interface class_department : NSObject

@property(nonatomic, assign) NSInteger dept_id;
@property(nonatomic, assign) NSInteger inst_id;
@property(nonatomic, strong) NSString *dept_name;
@property(nonatomic, strong) NSString *description_;

@end  

_

@interface class_department_list : NSObject

@property(nonatomic, strong) class_department *department;
@property(nonatomic, assign) BOOL needDelete;

@end

-

@interface sync_json : NSObject

@property(nonatomic, strong) NSMutableArray *json_department;
@property(nonatomic, strong) NSMutableArray *json_subjects;

@end

-

-(RKResponseDescriptor *)getResponseDescriptor
{

RKObjectMapping *class_department_mapping = [RKObjectMapping mappingForClass:[class_department class]];
[class_department_mapping addAttributeMappingsFromDictionary:@{
                                                               @"id":@"dept_id",
                                                           @"inst_id":@"inst_id",
                                                            @"dept_name":@"dept_name"
                                                           @"description":@"description_",
                                                       }];


RKObjectMapping *class_department_list_mapping = [RKObjectMapping mappingForClass:[class_department_list class]];
[class_department_list_mapping addAttributeMappingsFromDictionary:@{
                                                           @"needDelete":@"needDelete"
                                                           }];

[class_department_list_mapping addPropertyMapping:[RKRelationshipMapping
                                                   relationshipMappingFromKeyPath:@"json_department.department"
                                                   toKeyPath:@"department"
                                                   withMapping:class_department_mapping]];


RKObjectMapping *json_mapping = [RKObjectMapping mappingForClass:[sync_json class]];

[json_mapping addPropertyMapping:[RKRelationshipMapping
                                                   relationshipMappingFromKeyPath:@"json_department"
                                                   toKeyPath:@"json_department"
                                                   withMapping:class_department_list_mapping]];



NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:json_mapping
                                                                                        method:RKRequestMethodGET
                                                                                   pathPattern:nil
                                                                                       keyPath:@"json"
                                                                                   statusCodes:statusCodes];

return responseDescriptor;

}

OKay this is code i'm using for mapping the json. i got the result for 'needDelete' but mapping to class_department is not happen. Please give me a way to done this.

Thank you. Shinurag KR

1
  • Fixed. Thank you Klevison Matias Commented Mar 25, 2015 at 15:08

1 Answer 1

1

Sorry, but try to forget this ugly implementation. Mantle do everythig pretty easy for you. Project: https://github.com/Mantle/Mantle Example: http://www.objc.at/mantle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.