Parsing JSON to a predefined class in Objective C

后端 未结 5 1592

I have a json string like:

{
  \"a\":\"val1\",
  \"b\":\"val2\",
  \"c\":\"val3\"
}

And I have an objective C header file like:



        
5条回答
  •  半阙折子戏
    2021-02-02 04:19

    Use OCMapper to automate your mapping. it has the ability to automatically map all fields, and simple to use.

    https://github.com/aryaxt/OCMapper

    let request = Manager.sharedInstance.request(requestWithPath("example.com/users/5", method: .GET, parameters: nil))
    
    request.responseObject(User.self) { request, response, user, error in
        println(user.firstName)
    }
    

提交回复
热议问题