本文整理汇总了C++中json::Value::toStyledString方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::toStyledString方法的具体用法?C++ Value::toStyledString怎么用?C++ Value::toStyledString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::toStyledString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_vm_ip_by_name
// read /var/lib/libvirt/dnsmasq/default.leases to get ip
// domain must use DHCP
std::string VM_Controller::get_vm_ip_by_name(std::string domain_name){
LOG_INFO(domain_name);
Json::Value j;
virDomainPtr dom = virDomainLookupByName(_conn, domain_name.c_str());
if(dom == NULL){
Json::Value j;
j["status"] = "no such domain";
return j.toStyledString();
}
std::string mac = _get_vm_mac(dom);
LOG_INFO(mac);
virDomainFree(dom);
std::ifstream leases("/var/lib/libvirt/dnsmasq/default.leases");
while(!leases.eof()){
std::string line;
std::getline(leases, line);
DEBUG(line);
if(line == "")
break;
std::vector<std::string> v;
Tools::split(line, v, ' ');
if(v[1] == mac){
j["ip"] = v[2];
j["status"] = "ok";
return j.toStyledString();
}
}
leases.close();
j["status"] = "Could not find ip for the mac address";
return j.toStyledString();
}
示例2: doSetParams
void EvaluatePrequential::doSetParams() {
mDataSource = getParam("DataSource", "");
Json::Value jv = getParam("Learner");
if (! jv.isNull()) {
mLearnerName = jv["Name"].asString();
mLearnerParams = jv.toStyledString();
}
jv = getParam("Evaluator");
if (! jv.isNull()) {
mEvaluatorName = jv["Name"].asString();
mEvaluatorParams = jv.toStyledString();
}
else {
mEvaluatorName = "BasicClassificationEvaluator";
}
mReaderName = getParam("Reader", "");
if (mReaderName == "") {
jv = getParam("Reader");
if (! jv.isNull()) {
mReaderName = jv["Name"].asString();
mReaderParams = jv.toStyledString();
}
}
}
示例3: process_result
Json::Value Connection::process_result(const Json::Value& value) {
if(value.isObject()) {
Json::Value id = value["id"];
if(!id.isIntegral() or id.asInt() != 0) {
std::stringstream error;
error << value.toStyledString() << " is no id=0";
throw ConnectionError(error.str());
}
Json::Value jsonrpc = value["jsonrpc"];
if(!jsonrpc.isString()) {
std::stringstream error;
error << value.toStyledString() << " has no string member: jsonrpc";
throw ConnectionError(error.str());
}
Json::Value result = value["result"];
if(!result.isObject()) {
std::stringstream error;
error << value.toStyledString() << " has no object member: result";
throw ConnectionError(error.str());
}
return result;
} else {
std::stringstream error;
error << value.toStyledString() << " is no json object";
throw ConnectionError(error.str());
}
}
示例4: toJSON
std::string Zerobuf::toJSON() const
{
Json::Value rootJSON;
for( const auto& valueSchema : getSchema().fields )
addValueToJSON( rootJSON, valueSchema )
return rootJSON.toStyledString();
}
示例5: if
Expectations::Expectations(Json::Value jsonElement) {
if (jsonElement.empty()) {
fIgnoreFailure = kDefaultIgnoreFailure;
} else {
Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_IgnoreFailure];
if (ignoreFailure.isNull()) {
fIgnoreFailure = kDefaultIgnoreFailure;
} else if (!ignoreFailure.isBool()) {
SkDebugf("found non-boolean json value for key '%s' in element '%s'\n",
kJsonKey_ExpectedResults_IgnoreFailure,
jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
fIgnoreFailure = kDefaultIgnoreFailure;
} else {
fIgnoreFailure = ignoreFailure.asBool();
}
Json::Value allowedDigests = jsonElement[kJsonKey_ExpectedResults_AllowedDigests];
if (allowedDigests.isNull()) {
// ok, we'll just assume there aren't any AllowedDigests to compare against
} else if (!allowedDigests.isArray()) {
SkDebugf("found non-array json value for key '%s' in element '%s'\n",
kJsonKey_ExpectedResults_AllowedDigests,
jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else {
for (Json::ArrayIndex i=0; i<allowedDigests.size(); i++) {
fAllowedResultDigests.push_back(GmResultDigest(allowedDigests[i]));
}
}
}
}
示例6: save_login
bool save_login()
{
Json::Value login;
login["pwd"] = base64::base64_encode((UCHAR*)XorCrypt::Xor(login_pwd, XOR_PWD).c_str(), login_pwd.length());
login["user"] = login_name;
TCHAR szPath[MAX_PATH] = { 0 };
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath);
::PathAppend(szPath, APP_NAME);
if (!PathFileExists(szPath))
{
SHCreateDirectoryEx(NULL, szPath, NULL);
}
::PathAppend(szPath, LOGIN_DAT);
HANDLE hFile = CreateFile(szPath, GENERIC_WRITE | GENERIC_READ,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return false;
DWORD dwWritten = 0;
::WriteFile(hFile, login.toStyledString().c_str(), login.toStyledString().size(), &dwWritten, NULL);
::FlushFileBuffers(hFile);
::CloseHandle(hFile);
return true;
}
示例7: if
GmResultDigest::GmResultDigest(const Json::Value &jsonTypeValuePair) {
fIsValid = false;
if (!jsonTypeValuePair.isArray()) {
gm_fprintf(stderr, "found non-array json value when parsing GmResultDigest: %s\n",
jsonTypeValuePair.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else if (2 != jsonTypeValuePair.size()) {
gm_fprintf(stderr, "found json array with wrong size when parsing GmResultDigest: %s\n",
jsonTypeValuePair.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else {
// TODO(epoger): The current implementation assumes that the
// result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
Json::Value jsonHashValue = jsonTypeValuePair[1];
if (!jsonHashValue.isIntegral()) {
gm_fprintf(stderr,
"found non-integer jsonHashValue when parsing GmResultDigest: %s\n",
jsonTypeValuePair.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else {
fHashDigest = jsonHashValue.asUInt64();
fIsValid = true;
}
}
}
示例8: sendPosition
void LCBattleScene::sendPosition(CCPoint pos){
OBJ_GPoint point;
point.x = pos.x;
point.y = pos.y;
Json::Value root;
Json::Value jsPos;
jsPos["x"] = pos.x;
jsPos["y"] = pos.y;
root["success"] = true;
root["msg"] = "hello";
root["type"] = OBJ_TYPE_GPOINT;
root["jsondata"] = jsPos.toStyledString().c_str();
std::string str = root.toStyledString();
str = str + "\r\n";
//CCLOG("%s %s %s", root.toStyledString().c_str(), jsPos.toStyledString().c_str(), str.c_str());
OD_BYTEPTR buffer = (OD_BYTEPTR)malloc(1024);
memcpy(buffer, str.c_str() , 1024);
con->Send(buffer);
}
示例9: get_job_progress
std::string VM_Controller::get_job_progress(int job_id){
RSIClients * clients = RSIClients::get_instance();
int progress = clients->download_progress(job_id);
Json::Value j;
if(progress < 0){
j["status"] = "no such job";
return j.toStyledString();
}
j["status"] = "ok";
j["progress"] = progress;
return j.toStyledString();
}
示例10: JsonDeserialization
bool PlayingCards::JsonDeserialization(const std::string &sJsonPlayingCards, std::string &sErrorMessage)
{
Json::Reader jReader;
Json::Value jCards;
Json::Value jCard;
Card cCard;
if (jReader.parse(sJsonPlayingCards, jCards, false))
{
m_vCards.clear();
for (Json::ValueIterator it = jCards.begin(); it != jCards.end(); ++it)
{
jCard = (*it);
if (cCard.JsonDeserialization(jCard.toStyledString(), sErrorMessage))
{
m_vCards.push_back(cCard);
}
else
{
return false;
}
}
return true;
}
else
{
sErrorMessage = jReader.getFormattedErrorMessages();
return false;
}
}
示例11: actionWhisper
void Epoll::actionWhisper(Client* me, Json::Value &obj) {
if (
!obj["data"].isMember("uid") ||
!obj["data"].isMember("content")
) {
return;
}
int uid = obj["data"]["uid"].asInt();
Client *you = getClientByUID(uid);
if(!you) {
std::cout << "user uid:" << uid << " not exists!" << std::endl;
return;
}
Json::Value target;
target["uid"] = you->getUID();
target["name"] = "你";
Json::Value user;
user["uid"] = me->getUID();
user["name"] = me->getName();
Json::Value data;
data["user"] = user;
data["content"] = obj["data"]["content"].asString();
data["target"] = target;
Json::Value oops;
oops["code"] = Message::sWhisper;
oops["data"] = data;
std::cout << user["name"].asString() << "对" << you->getName() << "说:" << data["content"].asString() << std::endl;
you->send(oops.toStyledString());
}
示例12: encode
void Protocol::encode(std::string &value) const
{
Json::Value root;
JsonStream stream(root);
encode(stream);
std::string plain = root.toStyledString();
CCLOG("==== Client send:%s ====", plain.c_str());
if (needcrypt)
{
size_t length = plain.length();
char *temp = new char[length + sizeof(type)];
memcpy(temp, &type, sizeof(type));
rc4_state state;
rc4_init(&state, (const u_char *)OUTKEY.c_str(), OUTKEY.size());
rc4_crypt(&state, (const u_char *)plain.c_str(), (u_char *)(temp + sizeof(type)), length);
value.assign(temp, length + sizeof(type));
delete[] temp;
}
else
{
char *temp = new char[sizeof(type) + plain.length()];
memcpy(temp, &type, sizeof(type));
memcpy(temp + sizeof(type), plain.c_str(), plain.length());
value.assign(temp, plain.length() + sizeof(type));
}
}
示例13: takeoutClient
void Epoll::takeoutClient(Client* client) {
Json::Value oops;
oops["code"] = Message::sTakeOut;
client->send(oops.toStyledString());
_clients.erase(_clients.find(client->getFileDescripto()));
delete client;
}
示例14: SendDataThreadProc
UINT WINAPI SendDataThreadProc(LPVOID pParam) //发送数据的线程回调函数
{
//创建CPU占用率性能计数器
CPerformanceCounter CPUUseAge(TEXT("\\Processor(0)\\% Processor Time"));
//创建内存占用率性能计数器
CPerformanceCounter MemoryUseAge(TEXT("\\Memory\\Available MBytes"));
//创建磁盘IO性能计数器
CPerformanceCounter DiskUseAge(TEXT("\\PhysicalDisk(_Total)\\% Idle Time"));
while(true)
{
Sleep(100);
//得到当前计数器百分值
double nCPUUseAge = CPUUseAge.GetCurrentValue();
double nMemoryUseAge = 100 * (1 - MemoryUseAge.GetCurrentValue()/1976);
double nDiskUseAge = 100 - floor(DiskUseAge.GetCurrentValue());
//封装成JSON字符串
Json::Value json;
json["msg_type"] = Json::Value("data");
json["cpu_use"] = Json::Value(nCPUUseAge);
json["memory_use"] = Json::Value(nMemoryUseAge);
json["disk_use"] = Json::Value(nDiskUseAge);
string strText = json.toStyledString();
//发送性能信息
::send(sClient, strText.c_str(), strlen(strText.c_str()), 0);
}
return 1;
}
示例15: getRoot
void
CommandHandler::testAcc(std::string const& params, std::string& retStr)
{
std::map<std::string, std::string> retMap;
http::server::server::parseParams(params, retMap);
Json::Value root;
auto accName = retMap.find("name");
if (accName == retMap.end())
{
root["status"] = "error";
root["detail"] = "Bad HTTP GET: try something like: testacc?name=bob";
}
else
{
SecretKey key;
if (accName->second == "root")
{
key = getRoot(mApp.getNetworkID());
}
else
{
key = getAccount(accName->second.c_str());
}
auto acc = loadAccount(key, mApp, false);
if (acc)
{
root["name"] = accName->second;
root["id"] = PubKeyUtils::toStrKey(acc->getID());
root["balance"] = (Json::Int64)acc->getBalance();
root["seqnum"] = (Json::UInt64)acc->getSeqNum();
}
}
retStr = root.toStyledString();
}