本文整理汇总了C++中JsonObject::encode方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::encode方法的具体用法?C++ JsonObject::encode怎么用?C++ JsonObject::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject::encode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ABC_ERROR
Status
loginServerOtpPending(std::list<DataChunk> users, std::list<bool> &isPending)
{
const auto url = ABC_SERVER_ROOT "/v1/otp/pending/check";
std::string param;
std::map<std::string, bool> userMap;
std::list<std::string> usersEncoded;
for (const auto &u : users)
{
std::string username = base64Encode(u);
param += (username + ",");
userMap[username] = false;
usersEncoded.push_back(username);
}
JsonObject json;
ABC_CHECK(json.set("l1s", param));
HttpReply reply;
ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
ServerReplyJson replyJson;
ABC_CHECK(replyJson.decode(reply));
JsonArray arrayJson = replyJson.results();
size_t size = arrayJson.size();
for (size_t i = 0; i < size; i++)
{
json_t *pJSON_Row = arrayJson[i].get();
if (!pJSON_Row || !json_is_object(pJSON_Row))
return ABC_ERROR(ABC_CC_JSONError, "Error parsing JSON array element object");
json_t *pJSON_Value = json_object_get(pJSON_Row, "login");
if (!pJSON_Value || !json_is_string(pJSON_Value))
return ABC_ERROR(ABC_CC_JSONError, "Error otp/pending/login JSON");
std::string username(json_string_value(pJSON_Value));
pJSON_Value = json_object_get(pJSON_Row, ABC_SERVER_JSON_OTP_PENDING);
if (!pJSON_Value || !json_is_boolean(pJSON_Value))
return ABC_ERROR(ABC_CC_JSONError, "Error otp/pending/pending JSON");
if (json_is_true(pJSON_Value))
{
userMap[username] = json_is_true(pJSON_Value);
}
}
isPending.clear();
for (auto &username: usersEncoded)
{
isPending.push_back(userMap[username]);
}
return Status();
}
示例2: Status
Status
loginServerLobbyReply(const std::string &id, JsonPtr &lobbyReplyJson)
{
const auto url = ABC_SERVER_ROOT "/v2/lobby/" + id;
JsonObject requestJson;
ABC_CHECK(requestJson.set("data", lobbyReplyJson));
HttpReply reply;
ABC_CHECK(AirbitzRequest().request(reply, url, "POST", requestJson.encode()));
ServerReplyJson replyJson;
ABC_CHECK(replyJson.decode(reply));
return Status();
}
示例3: arrayJson
Status
loginServerMessages(JsonPtr &result, const std::list<std::string> &usernames)
{
const auto url = ABC_SERVER_ROOT "/v2/messages";
// Compute all userIds:
JsonArray loginIds;
std::map<std::string, std::string> loginIdMap;
for (const auto &username: usernames)
{
std::shared_ptr<LoginStore> store;
ABC_CHECK(LoginStore::create(store, username));
const auto loginId = base64Encode(store->userId());
loginIds.append(json_string(loginId.c_str()));
loginIdMap[loginId] = username;
}
JsonObject request;
ABC_CHECK(request.set("loginIds", loginIds));
// Make the request:
HttpReply reply;
ABC_CHECK(AirbitzRequest().request(reply, url, "POST", request.encode()));
ServerReplyJson replyJson;
ABC_CHECK(replyJson.decode(reply));
// Insert the original usernames into the results:
JsonArray arrayJson(replyJson.results());
size_t size = arrayJson.size();
for (size_t i = 0; i < size; i++)
{
JsonObject objectJson(arrayJson[i]);
const auto loginId = objectJson.getString("loginId", nullptr);
if (!loginId) continue;
const auto username = loginIdMap.find(loginId);
if (username == loginIdMap.end()) continue;
ABC_CHECK(objectJson.set("username", username->second));
}
result = arrayJson;
return Status();
}
示例4: options
/**
* \brief Function to solve the jobOutputGetCompletedJobs service
* \param pb is a structure which corresponds to the descriptor of a profile
* \return raises an exception on error
*/
int
solveJobOutPutGetCompletedJobs(diet_profile_t* pb) {
std::string authKey;
std::string machineId;
std::string serializedOptions;
std::string jobListsSerialized;
int mapperkey;
std::string cmd;
diet_string_get(pb, 0, authKey);
diet_string_get(pb, 1, machineId);
diet_string_get(pb, 2, serializedOptions);
// reset profile to handle result
diet_profile_reset(pb, 2);
try {
//MAPPER CREATION
Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME);
mapperkey = mapper->code("vishnu_get_completed_jobs_output");
mapper->code(machineId, mapperkey);
mapper->code(serializedOptions, mapperkey);
cmd = mapper->finalize(mapperkey);
JsonObject options(serializedOptions);
JobOutputServer jobOutputServer(authKey, machineId);
TMS_Data::ListJobResults_ptr jobResults = jobOutputServer.getCompletedJobsOutput(&options);
::ecorecpp::serializer::serializer _ser;
jobListsSerialized = _ser.serialize_str(jobResults);
std::ostringstream ossFileName ;
size_t nbResult = jobResults->getResults().size() ;
for(size_t i = 0; i < nbResult; ++i) {
std::ostringstream missingFiles;
missingFiles.clear() ;
ossFileName << vishnu::getResultFiles(*jobResults->getResults().get(i), true);
}
std::string outputInfo = bfs::unique_path(boost::filesystem::temp_directory_path().string()+"/vishnu-outdescr%%%%%%%").string();
vishnu::saveInFile(outputInfo, ossFileName.str());
JsonObject data;
data.setProperty("infofile", outputInfo);
data.setProperty("joblist", jobListsSerialized);
// set result
diet_string_set(pb, 0, "success");
diet_string_set(pb, 1, data.encode());
FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, "");
} catch (VishnuException& e) {
try {
FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDFAILED, "");
} catch (VishnuException& fe) {
e.appendMsgComp(fe.what());
}
// set result
diet_string_set(pb, 0, "error");
diet_string_set(pb, 1, e.what());
}
return 0;
}