我正在使用json-spirit为我的ws++服务器解析json。
我正在比较用于验证注册过程、确认登录、电子邮件、密码等的字符串。
json-spirit的get_str()返回const std::string&。
我试过==,compare,甚至strcmp。当我尝试将函数返回与“1linder”(都在if比较语句中)进行比较时,terminate called after throwing an instance of 'std::runtime_error' what(): value type is 0 not 2会使程序崩溃。
这个函数可以使用1行代码返回吗?
发布于 2013-07-09 09:30:19
猜测一下:我认为您的源json并没有提供您认为的值类型方面的信息。
我不熟悉json-spirit,但您的链接中有这样一段:
You obtain the Value's type by calling Value::type(). You can then call the appropriate getter function. Generally, you will know a file's format, so you will know what type the JSON values should have. A std::runtime_error exception is thrown if you try to get a value of the wrong type, for example, if you try to extract a string from a value containing an integer.
这听起来与您看到的错误非常相似。我猜json-spirit认为你的字符串根本不是字符串。当你试图在不是字符串的东西上调用get_str()时(不管什么定义为“0”类型),它会抛出一个异常。
编辑:在json-spirit's source中查找,键入"0“是NULL_TYPE
https://stackoverflow.com/questions/17538465
复制相似问题