jwvg0425 / cppson Goto Github PK
View Code? Open in Web Editor NEWcpp json utility
License: MIT License
cpp json utility
License: MIT License
json file parsing is so slow and inefficient, unstable.
pretty json!
FIELD macro create meta_XXX field. remove them.
instance data to json file
add using jsoncpp version.
In standard json format, json can accept 'null', 'false' and 'true' values. but your implementation cannot parse boolean types which not wrapped with quotes("").
JSON_CLASS(Foo)
{
public:
FIELD(bool, b);
}
{
"b" : true
}
#define CATCH_CONFIG_MAIN
#include "catch.h"
TEST_CASE("parse from string") {
JSON_CLASS(NestedObject)
{
public:
FIELD(int, _int);
FIELD(bool, _bool);
};
JSON_CLASS(TestObject)
{
public:
FIELD(int, _int);
FIELD(bool, _bool);
//FIELD(float, _float);
FIELD(std::string, _string);
FIELD(std::vector<int>, _vector);
FIELD(NestedObject, _nested);
};
TestObject obj;
obj.ParseFromString(
"{"
/* for 'basic types' section */
"\"_int\" : 5,"
"\"_bool\" : \"true\","
//"\"_float\" : 2.5,"
"\"_string\" : \"hello\","
/* for 'std::vector type' section */
"\"_vector\" : [1, 2, 3 ,4 ,5],"
/* for 'std::map type' section */
//"\"_vector\" : [1, 2, 3 ,4 ,5],"
/* for 'nested object' section */
"\"_nested\" : {"
"\"_int\" : 14,"
"\"_bool\" : \"false\""
"}"
"}");
SECTION("basic types") {
REQUIRE(obj._int == 5);
REQUIRE(obj._bool == true);
//REQUIRE(obj._float == 5.0f);
REQUIRE(obj._string == "hello");
}
SECTION("std::vector type") {
REQUIRE(obj._vector.size() == 5);
REQUIRE(obj._vector == (std::vector<int>{1, 2, 3, 4, 5}));
}
SECTION("std::map type") {
/* .... */
}
SECTION("nested object") {
REQUIRE(obj._nested._int == 14);
REQUIRE(obj._nested._bool == false);
}
}
JSON_CLASS can't inherit.
https://github.com/jwvg0425/cppson/blob/master/src/cppson.hpp#L179
https://github.com/jwvg0425/cppson/blob/master/src/cppson.hpp#L229
auto
-> auto &
https://github.com/jwvg0425/cppson/blob/master/src/cppson.hpp#L229
push_back(std::move(value));
https://github.com/jwvg0425/cppson/blob/master/src/cppson.hpp#L18
https://github.com/jwvg0425/cppson/blob/master/src/cppson.hpp#L18
JsonValue
-> JsonValue&
https://github.com/jwvg0425/cppson/blob/master/src/cppson.hpp#L234
push_back(std::move(p));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.