Skip to content

Examples (zh)

haibo2.liu edited this page Sep 29, 2022 · 2 revisions

示例代码

自定义 User 类的序列化

#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;
}

一个HTTP接口的伪代码

example

Overview

  • Quick start ( en | zh )
  • Examples ( en | zh )

Features

  • Value operation ( en | zh )
  • Serialization ( en | zh )
  • Custom conversion ( en | zh )
  • Encoding support ( en | zh )

Other

  • Q&A ( en | zh )
  • Advanced ( en | zh )

Clone this wiki locally