c++jsoncasablanca

Convert Json String to C++ Object using Casablanca REST SDK


Good Morning, iam using the casablanca REST SDK.

Is there any simple way to convert a json string in an object and back as shown in this example? (http://www.newtonsoft.com/json/help/html/serializingjson.htm)

Update I found a little function that could do what i need. When i use the function i get errors as shown in the picture. Have someone a solution for that?

User GetUser(http_request *Reques)
{
     return Request->body().extract<User>().get();
}

Error

greetings cazza


Solution

  • And here the snipped

     bool User::LoadNewUser(json::value user)
    {
        try{
            this->SetName(utility::conversions::to_utf8string(user[L"UserName"].as_string()));
            this->SetMail(utility::conversions::to_utf8string(user[L"Email"].as_string()));
            this->SetScreenName(utility::conversions::to_utf8string(user[L"ScreenName"].as_string()));
    
    
    UserResponse Usermanagement::CreateNewUser(http_request *Request)
    {
        UserResponse Resp;
    
        if (this->LoadNewUser(Request->extract_json().get()))