Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserializing Issue with string type. #7

Closed
jaychanda opened this issue Mar 19, 2019 · 1 comment
Closed

Deserializing Issue with string type. #7

jaychanda opened this issue Mar 19, 2019 · 1 comment

Comments

@jaychanda
Copy link

struct ConnectionProp{
int connectionId;
std::string connectionName;
double timeout;
XTOSTRUCT(M(connectionId,timeout),O(connectionName));
};

ConnectionProp x;
x2struct::X::loadjson(decodedstr, x, false);

In ConnectionProp object, connectionName property is getting a value of "".

Json is :"{"connectionId":3,"connectionName":"JAY","timeout":3.55566}

@xyz347
Copy link
Owner

xyz347 commented Mar 19, 2019

I try this code:

#include <iostream>
#include "x2struct/x2struct.hpp"

using namespace std;

struct ConnectionProp{
    int connectionId;
    std::string connectionName;
    double timeout;
    XTOSTRUCT(M(connectionId,timeout),O(connectionName));
};

int main(int argc, char*argv[]) {
    ConnectionProp x;
    string jstr="{\"connectionId\":3,\"connectionName\":\"JAY\",\"timeout\":3.55566}";
    x2struct::X::loadjson(jstr, x, false); 
    cout<<x.connectionId<<endl;
    cout<<x.connectionName<<endl;
    cout<<x.timeout<<endl;
    return 0;
}

output is :

3
JAY
3.55566

@xyz347 xyz347 closed this as completed Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants