如何在swift中使用restkit映射这个json?还是客观的?只是不使用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"}]
我有这段代码,但它不起作用。
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)")
}
);