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

对于类型不匹配的情况下,x2struct::X::loadjson阻塞线程 #41

Closed
ErikZhou opened this issue Nov 23, 2020 · 2 comments
Closed

Comments

@ErikZhou
Copy link

eg
定义:
struct input
{
std::string name;
std::string id;
XTOSTRUCT(M(name,id));
};
json:
{
"name": "Tom",
"id":1
}
id 类型为int而不是string
没有错误,没有异常。
这个问题比较严重

@xyz347
Copy link
Owner

xyz347 commented Nov 23, 2020

#include <iostream>
#include "x2struct/x2struct.hpp" // 包含这个头文件

using namespace std;

struct input {
    string name;
    string id;
    XTOSTRUCT(O(name, id));
};

int main(int argc, char *argv[]) {
    string s = "{\"name\":\"Tom\", \"id\":1}";
    input in;
    x2struct::X::loadjson(s, in, false);
    return 0;
}

output:

terminate called after throwing an instance of 'std::runtime_error'
  what():  IsString()[id]
Aborted (core dumped)

你看看是不是上层有catch?

@ErikZhou
Copy link
Author

ErikZhou commented Dec 5, 2020

可以catch ,谢谢

@ErikZhou ErikZhou closed this as completed Dec 5, 2020
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