本文整理汇总了C++中json::Value::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::clear方法的具体用法?C++ Value::clear怎么用?C++ Value::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tokenize
TEST(MinibarRouter,Unittest){
RouteNode root;
Json::Value pathValues;
TokenSet test = tokenize("foo/bar/baz","/");
// insert route
root.addRoute(test,42);
root.addRoute(tokenize("foo/*/gorf","/"),13);
root.addRoute(tokenize("foo/bar/baz/:gorf","/"),29);
// prevent duplicates
ASSERT_THROW(root.addRoute(test,42),MinibarException);
// matching
pathValues.clear();
ASSERT_TRUE(root.matchRoute(tokenize("x/y/z","/"),pathValues) == RouteNode::NO_ROUTE_MATCH);
ASSERT_TRUE(pathValues.empty());
pathValues.clear();
ASSERT_TRUE(root.matchRoute(tokenize("foo/bar/baz","/"),pathValues) == 42);
ASSERT_TRUE(pathValues.empty());
pathValues.clear();
ASSERT_TRUE(root.matchRoute(tokenize("foo/bar/baz/goat","/"),pathValues) == 29);
ASSERT_TRUE(pathValues.isMember("gorf"));
ASSERT_TRUE(pathValues["gorf"].asString().compare("goat") == 0);
}
示例2: Enum_Drectory
void Enum_Drectory(void *cmd)
{
Json::FastWriter fast_writer;
Json::Value root;
string Base64Result;
cmdinfo *pci=(cmdinfo*)cmd;
if (pci->cmd_content.compare("/")==0)
{
string utf8_drive;
//Msg("获取驱动器\r\n");
GetDirverInfo(&root);
ANSIToUTF8(fast_writer.write(root).c_str(),&utf8_drive);
Base64Encode(reinterpret_cast<const unsigned char*>(utf8_drive.c_str()),utf8_drive.length(),Base64Result);
Replace_plus(Base64Result);
SubmitResult(pci,Base64Result.c_str());
Base64Result.erase();
utf8_drive.erase();
root.clear();
}
else
{
//Msg("获取文件夹列表\r\n");
Enum_Current_Drectory((char *)pci->cmd_content.c_str(),&root);
Base64Encode(reinterpret_cast<const unsigned char*>(fast_writer.write(root).c_str()),fast_writer.write(root).length(),Base64Result);
Replace_plus(Base64Result);
SubmitResult(pci,Base64Result.c_str());
Base64Result.erase();
root.clear();
}
}
示例3: main
int main(int argc, char** argv)
{
if (argc!=3)
{
printf("usage: c.out <gateway server> <gateway server port>");
return 1;
}
try
{
cout<<"client test"<<endl;
Json::Value root;
root["req_type"] = "put";
root["req_args"]["key"] = "ly232";
root["req_args"]["value"] = "Lin Yang";
root["sync"] = "true"; //tell server to ensure consistency before ack
//alternatively, if this field is not specified,
//server will be eventually consistent (i.e. default false)
Json::StyledWriter writer;
std::string outputConfig = writer.write(root);
client clt(argv[1], atoi(argv[2]));
std::string reply = clt.sendstring(outputConfig.c_str());
std::cout<<"reply="<<reply<<std::endl;
root.clear();
root["req_type"] = "get";
root["req_args"]["key"] = "ly232";
outputConfig = writer.write(root);
reply = clt.sendstring(outputConfig.c_str());
std::cout<<"reply="<<reply<<std::endl;
root.clear();
root["req_type"] = "delete";
root["req_args"]["key"] = "ly232";
outputConfig = writer.write(root);
reply = clt.sendstring(outputConfig.c_str());
std::cout<<"reply="<<reply<<std::endl;
root.clear();
root["req_type"] = "get";
root["req_args"]["key"] = "ly232";
outputConfig = writer.write(root);
reply = clt.sendstring(outputConfig.c_str());
std::cout<<"reply="<<reply<<std::endl;
root.clear();
root["req_type"] = "exit";
outputConfig = writer.write(root);
reply = clt.sendstring(outputConfig.c_str());
std::cout<<"reply="<<reply<<std::endl;
}
catch(int e)
{
cout<<"error code = "<<e<<endl;
}
return 0;
}
示例4: Query_all_mysql
/**
* @return json string
* eg:
*
* {
* "userNum":3,
* "Users":
* [
* {
* "m_strUserName":"syq",
* "m_strUserPhone":"15237872320",
* "m_strUserDepartment":"software college"
* },
* {
* "m_strUserName":"claire",
* "m_strUserPhone":"15237872320",
* "m_strUserDepartment":"software college"
* }
* ]
* }
*
*/
string DBConn::Query_all_mysql(string sql, string ObjectName) {
Json::Value root;
Json::Value arrayObj;
Json::Value item;
int t = mysql_real_query(&mysql, sql.c_str(),
(unsigned int) strlen(sql.c_str()));
if (t == -1) {
cout << "query failed:%s\n" << mysql_errno(&mysql)
<< mysql_error(&mysql) << endl;
} else {
res = mysql_store_result(&mysql); //返回查询的全部结果集
//获取表的列数
//int numb=mysql_num_fields(res);
//printf("name: %s count: %d\n", namebuf[i], rows);
//获取并输出表头
field = mysql_fetch_fields(res);
//int length=mysql_fetch_lengths(res);
int length = mysql_num_rows(res);
int userNum = 0;
int i = 1;
while (row = mysql_fetch_row(res)) { //mysql_fetch_row取结果集的下一行
for (t = 0; t < mysql_num_fields(res); t++) { //结果集的列的数量
item[field[t].name] = Json::Value(row[t]);
}
arrayObj.append(item);
item.clear();
userNum++;
}
root["Num"] = Json::Value(userNum);
root[ObjectName] = arrayObj;
return root.toStyledString();
}
}
示例5: extractOptions
Options PipelineReaderJSON::extractOptions(Json::Value& node)
{
Options options;
for (const std::string& name : node.getMemberNames())
{
if (node[name].isString())
options.add(name, node[name].asString());
else if (node[name].isInt())
options.add(name, node[name].asInt64());
else if (node[name].isUInt())
options.add(name, node[name].asUInt64());
else if (node[name].isDouble())
options.add(name, node[name].asDouble());
else if (node[name].isBool())
options.add(name, node[name].asBool());
else if (node[name].isNull())
options.add(name, "");
else
throw pdal_error("JSON pipeline: Value of stage option '" +
name + "' cannot be converted.");
}
node.clear();
return options;
}
示例6: GetValueFromDapiResponse
bool GetValueFromDapiResponse(Json::Value& value, const DAPIResponse& response)
{
bool bSuccess = true;
// Conditionals to avoid unecessary assert
if(value.type() == Json::nullValue ||
value.type() == Json::arrayValue ||
value.type() == Json::objectValue) {
value.clear();
}
string valueString;
DapiMgr::GetStringFromDapiResponse(valueString, response);
uint64_t length = valueString.length();
const char* c = valueString.c_str();
if (length != 0)
{
Json::Reader reader;
bool parsingSuccessful = reader.parse(c, c + length, value);
if (!parsingSuccessful)
{
std::cout << "Failed to parse configuration\n" << reader.getFormattedErrorMessages();
bSuccess = false;
}
}
return bSuccess;
}
示例7: Format
void SliceOrdering::Format(Json::Value& result) const
{
result = Json::objectValue;
result["Type"] = (isVolume_ ? "Volume" : "Sequence");
Json::Value tmp = Json::arrayValue;
for (size_t i = 0; i < GetInstancesCount(); i++)
{
tmp.append(GetBasePath(ResourceType_Instance, GetInstanceId(i)) + "/file");
}
result["Dicom"] = tmp;
Json::Value slicesShort = Json::arrayValue;
tmp.clear();
for (size_t i = 0; i < GetInstancesCount(); i++)
{
std::string base = GetBasePath(ResourceType_Instance, GetInstanceId(i));
for (size_t j = 0; j < GetFramesCount(i); j++)
{
tmp.append(base + "/frames/" + boost::lexical_cast<std::string>(j));
}
Json::Value tmp2 = Json::arrayValue;
tmp2.append(GetInstanceId(i));
tmp2.append(0);
tmp2.append(GetFramesCount(i));
slicesShort.append(tmp2);
}
result["Slices"] = tmp;
result["SlicesShort"] = slicesShort;
}
示例8: ToJson
void Settings::ToJson(Json::Value& o_json)
{
o_json.clear();
o_json["defaults"] = Json::Value();
o_json["SplitTunnel"] = Settings::SplitTunnel() ? TRUE : FALSE;
o_json["defaults"]["SplitTunnel"] = SPLIT_TUNNEL_DEFAULT;
o_json["VPN"] = (Settings::Transport() == TRANSPORT_VPN) ? TRUE : FALSE;
o_json["defaults"]["VPN"] = FALSE;
o_json["LocalHttpProxyPort"] = Settings::LocalHttpProxyPort();
o_json["defaults"]["LocalHttpProxyPort"] = NULL_PORT;
o_json["LocalSocksProxyPort"] = Settings::LocalSocksProxyPort();
o_json["defaults"]["LocalSocksProxyPort"] = NULL_PORT;
o_json["SkipUpstreamProxy"] = Settings::SkipUpstreamProxy() ? TRUE : FALSE;;
o_json["defaults"]["SkipUpstreamProxy"] = SKIP_UPSTREAM_PROXY_DEFAULT;
o_json["UpstreamProxyHostname"] = Settings::UpstreamProxyHostname();
o_json["defaults"]["UpstreamProxyHostname"] = UPSTREAM_PROXY_HOSTNAME_DEFAULT;
o_json["UpstreamProxyPort"] = Settings::UpstreamProxyPort();
o_json["defaults"]["UpstreamProxyPort"] = NULL_PORT;
o_json["EgressRegion"] = Settings::EgressRegion();
o_json["defaults"]["EgressRegion"] = EGRESS_REGION_DEFAULT;
o_json["SystrayMinimize"] = Settings::SystrayMinimize() ? TRUE : FALSE;;
o_json["defaults"]["SystrayMinimize"] = SYSTRAY_MINIMIZE_DEFAULT;
}
示例9: expectFill
void expectFill (
std::string const& label,
Type status,
Status::Strings messages,
std::string const& message)
{
value_.clear ();
fillJson (Status (status, messages));
auto prefix = label + ": ";
expect (!value_.empty(), prefix + "No value");
auto error = value_[jss::error];
expect (!error.empty(), prefix + "No error.");
auto code = error[jss::code].asInt();
expect (status == code, prefix + "Wrong status " +
std::to_string (code) + " != " + std::to_string (status));
auto m = error[jss::message].asString ();
expect (m == message, m + " != " + message);
auto d = error[jss::data];
size_t s1 = d.size(), s2 = messages.size();
expect (s1 == s2, prefix + "Data sizes differ " +
std::to_string (s1) + " != " + std::to_string (s2));
for (auto i = 0; i < std::min (s1, s2); ++i)
{
auto ds = d[i].asString();
expect (ds == messages[i], prefix + ds + " != " + messages[i]);
}
}
示例10: GetFriendList
Json::Value WebAPI::GetFriendList(std::string accessToken) {
Debug("[DEBUG] Trying to get friend list");
Json::Value result;
Json::Reader reader;
std::string url = "https://api.steampowered.com/ISteamUserOAuth/GetFriendList/v0001";
url = url + "?access_token=" + accessToken + "&relationship=friend,requestrecipient";
// Read the friend list of the bot
WriteDataInfo pageInfo = this->GetPage(this->webAPIClient, url, USER_AGENT_APP, nullptr);
// Valid result?
if (!pageInfo.error.empty()) {
result["success"] = false;
result["error"] = "Failed to receive friend list. Error: '" + pageInfo.error + "'";
return result;
}
result.clear();
if (!reader.parse(pageInfo.content, result)) {
result["success"] = false;
result["error"] = "Failed to parse friend list. Error: '" + reader.getFormattedErrorMessages() + "'";
return result;
}
Debug("[DEBUG] Got friend list");
result["success"] = true;
return result;
}
示例11: readInto
bool File::readInto(Json::Value &root, bool keepComments) const
{
if(!exists())
{
Ogre::String msg = "could not open :" + fullPath() + ": file not found.";
if(Debug::isInit)
Debug::error(STEEL_METH_INTRO, msg).endl();
else
std::cerr << STEEL_METH_INTRO.c_str() << msg.c_str() << std::endl;
return false;
}
Json::Reader reader;
Ogre::String content = read(false);
root.clear();
if(!reader.parse(content, root, keepComments))
{
Ogre::String msg = "Could not parse content:" + reader.getFormatedErrorMessages() + "\non :" + content;
if(Debug::isInit)
Debug::error(STEEL_METH_INTRO, msg).endl();
else
std::cerr << STEEL_METH_INTRO.c_str() << msg.c_str() << std::endl;
return false;
}
return true;
}
示例12: main
int main(int argv,char *argc[])
{
int err = 0 ;
ifstream s;
ofstream out;
Json::Value root;
do {
if ( 3 != argv ) {
cout<<"please check you argument"<<endl;
Usage();
err = 1;
break;
}
s.open(argc[1],ifstream::in);
s>>root;
Parse(root);
} while (0);
root.clear();
root["firstname"]="zhengying";
root["lastname"]="ming";
root["age"]=22;
root["path"]=Json::Value();
out.open(argc[2],ofstream::out);
out<<root.toStyledString();
out.close();
s.close();
return err;
}
示例13: leave_test_case
void leave_test_case(int line, const char* file, const char* test_name)
{
executing = false;
for (auto &id : test_data.getMemberNames())
test_case[id] = test_data[id];
test_data.clear();
test_case["result"] = current_result;
test_case["result_ex"] = current_result_ex;
test_case["line_exit"] = line;
data["cases"].append(test_case);
test_case.clear();
}
示例14: protocol_test
static void protocol_test(FILE *bei, FILE *beo) {
Json::Value req;
Json::Value res;
req["command"] = "initialize";
req["debug"] = true;
write_request(req, bei);
read_response(res, beo);
if (res["version"].asString() != WEB_EXTENSION_VERSION) {
std::cerr << "Version mismatch" << std::endl;
exit(EXIT_FAILURE);
}
req.clear();
res.clear();
req["command"] = "get_certificates";
write_request(req, bei);
read_response(res, beo);
if (!res["certificates"][0].isMember("der")) {
std::cerr << "Failed to get certificate" << std::endl;
exit(EXIT_FAILURE);
}
std::string der = res["certificates"][0]["der"].asString();
req.clear();
res.clear();
req["command"] = "sign_data";
req["certificate"] = der;
req["data"] = "SGVsbG8sIHdvcmxkIQo=";
write_request(req, bei);
read_response(res, beo);
static const char ERROR[] = "error:";
if (!res["result"].asString().compare(0, strlen(ERROR), ERROR)) {
std::cerr << "Signature error" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Test passed" << std::endl;
}
示例15: create_request
void create_request(Json::Value &request, const string &method, int id = 1) {
request.clear();
request["jsonrpc"] = "2.0";
request["id"] = id;
request["method"] = method;
}