-
Notifications
You must be signed in to change notification settings - Fork 67
Examples (zh)
haibo2.liu edited this page Sep 29, 2022
·
2 revisions
#include <string>
#include <iostream>
#include <sstream>
#include <configor/json.hpp>
using namespace configor;
// 用户类
struct User
{
int user_id;
std::string user_name;
CONFIGOR_BIND(json::value, User, REQUIRED(user_id), OPTIONAL(user_name));
};
int main(int argc, char** argv)
{
std::stringstream s("{\"user_id\": 10001, \"user_name\": \"John\"}");
// 解析json内容,并反序列化到user对象
User user;
s >> json::wrap(user);
// 序列化user对象并输出
std::cout << json::wrap(user) << std::endl;
// Output:
// {"user_id":10001,"user_name":"John"}
return 0;
}