chenluhua1980
2025-12-11 260b30211b44fea725a5a6fb5d72c1d0581eccbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include <string>
#include <json/json.h>
 
namespace SERVO { class CGlass; }
 
/**
 * @brief CGlass <-> JSON µÄ×îС¹¤¾ßÀࣨ»ùÓÚ JsonCpp£©
 *
 * - ²»ÐÞ¸ÄÈκÎÏÖÓÐÀàÍ·Îļþ
 * - ¼æÈÝÀϰæ JsonCpp£¨ÎÞ Json::Int64/UInt64/asInt64£©
 * - Ð´¿â£ºToString / ToPrettyString
 * - ¶Á¿â£ºFromString£¨·µ»Ø true/false£©
 */
class GlassJson {
public:
    // ºËÐÄ£º¶ÔÏó <-> Json::Value
    static Json::Value ToJson(const SERVO::CGlass& g);
    static void FromJson(const Json::Value& j, SERVO::CGlass& g);
 
    // ±ã½Ý£º¶ÔÏó <-> ½ô´Õ×Ö·û´®
    static std::string ToString(const SERVO::CGlass& g);                    // ½ô´Õ
    static bool FromString(const std::string& text, SERVO::CGlass& g,
        std::string* err = nullptr);                     // ½âÎöʧ°Ü·µ»Ø false
 
// ±ã½Ý£º¶ÔÏó <-> ÃÀ»¯×Ö·û´®
    static std::string ToPrettyString(const SERVO::CGlass& g);              // ÃÀ»¯
};