我正在使用 libjson 在 C++ 中解析 JSON 文件。我想知道您是否可以为地图做类似 PHP 样式的表示法:
只是一些伪代码:
mapObj["id"] = 4;
mapObj["tags"] = vector {"Foo", "Bar"};
structMapObj = {
{"name", "FooBar"},
{"size", 1234567},
{"date", "2014-12-24"}
};
mapObj["file"] = anotherMapObject;
// for the vector
mapObj["tags"][0];
mapObj["tags"][1];
mapObj["tags"].size();
mapObj["tags"].pushBack("Foo");
// for the map
mapObj["file"]["name"]
...
是否有可能收到这样的结果?
也许是 BaseClass 中当前类型的枚举?
myObj["key"].getType; // returns a 1 for example an INT
我尝试使用 BaseClass 和模板类来实现它,但我无法遍历该对象。或者我什至应该为我的 BaseClass 重载运算符?或者是否有必要为每种情况(映射类型对象的类、int 类型的类、字符串等)继承 BaseClass?
我现在有点绝望。只需要有人带领我走向正确的方向:-P
PS:我不想使用 boost :-/
非常感谢,
丹尼尔