JSONCPP bug


method_cfg["input_method"][0].asString()

报错误:

test1.cpp:40:46: error: ambiguous overload for ‘operator[]’ in ‘method_cfg.Json::Value::operator[](((const char*)"input_method"))[0]’
test1.cpp:40:46: note: candidates are:
/usr/include/json/value.h:277:14: note: Json::Value& Json::Value::operator[](Json::Value::UInt)
/usr/include/json/value.h:281:20: note: const Json::Value& Json::Value::operator[](Json::Value::UInt) const
/usr/include/json/value.h:294:14: note: Json::Value& Json::Value::operator[](const char*)
/usr/include/json/value.h:296:20: note: const Json::Value& Json::Value::operator[](const char*) const
/usr/include/json/value.h:298:14: note: Json::Value& Json::Value::operator[](const string&)
/usr/include/json/value.h:300:20: note: const Json::Value& Json::Value::operator[](const string&) const


原因和解答:

原因很简单,当是常量值0的时候,无法确定把它当作是 UINT 还是const char*,string来处理。

使用method_cfg["input_method"][0U].asString()或者使用变量 int n=0来代替

你可能感兴趣的:(JSONCPP bug)