CreoPluging9.0/JsonLite.h
2026-01-15 16:23:23 +08:00

45 lines
838 B
C++

#pragma once
#include <cctype>
#include <cstdlib>
#include <string>
#include <unordered_map>
namespace jsonlite {
struct Value {
enum class Type { Null, Bool, Number, String };
Type type = Type::Null;
bool b = false;
double n = 0.0;
std::string s;
static Value Null() { return Value{}; }
static Value Bool(bool v) {
Value x;
x.type = Type::Bool;
x.b = v;
return x;
}
static Value Number(double v) {
Value x;
x.type = Type::Number;
x.n = v;
return x;
}
static Value String(std::string v) {
Value x;
x.type = Type::String;
x.s = std::move(v);
return x;
}
};
using Object = std::unordered_map<std::string, Value>;
bool ParseObject(const std::string& input, Object& out, std::string& err);
std::string EscapeString(const std::string& s);
} // namespace jsonlite