0

How mapping this json using restkit in swift? or objective-c? Only not use coredata.

[{"one":"1","two":"2","three":"3","four":"4"}, {"one":"1","two":"2","three":"3","four":"4"}, {"one":"1","two":"2","three":"3","four":"4"}]

I have this code, but it's not work.

let postMapping: RKObjectMapping = RKObjectMapping(for: GetAddress.self)
postMapping.addAttributeMappings(from: ["one", "two", "three", "four"])

let statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClass.successful)
let resDescriptor = RKResponseDescriptor(mapping: postMapping, method: RKRequestMethod.GET, pathPattern: "/test", keyPath: nil, statusCodes: statusCodes)

let url = NSURL(string: "http://test.com/path")
let addURL = "test/code" 

let objectManager = RKObjectManager(baseURL: url as URL!)

objectManager?.addResponseDescriptor(resDescriptor)
objectManager?.getObjectsAtPath(addURL, parameters: nil,
    success: { operation, mappingResult in
        let post: GetClass = mappingResult!.firstObject as! GetClass
        print("one: \(post.one!)")
        print("two: \(post.two!)")
    },
    failure:{ operation, error in
        print("Error loading metric list': \(error!.localizedDescription)")
    }
);
Magic Max
  • 21
  • 3
  • Probably, you should add a description of what exactly goes wrong. Do you have any logs? If not, turn RestKit logging on by adding the following lines of code to your didFinishLaunchingWithOptions method: RKLogConfigureByName("RestKit/Network", RKLogLevelTrace); RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); – Stas Dec 19 '16 at 17:49
  • Any information about the issue? – ciccioska Feb 14 '17 at 15:09

0 Answers0