本文整理汇总了C++中json::Value::type方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::type方法的具体用法?C++ Value::type怎么用?C++ Value::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Translate
const std::string Translate(const std::string& key, const std::string& originalText) {
if ( LoadScriptTranslation() ) {
std::vector<std::string> tokens;
IuStringUtils::Split(key, ".", tokens, -1);
Json::Value root = *translationRoot;
int count = tokens.size();
for ( int i = 0; i < count; i++ ) {
std::string token = tokens[i];
if ( !root.isMember(token) ) {
break;
}
root = root[token];
if ( root.type() != Json::objectValue && i+1 != count ) {
break;
}
if ( i+1 == count && root.type() == Json::stringValue ) {
return root.asString();
}
}
}
#ifndef IU_CLI
return IuCoreUtils::WstringToUtf8((LPCTSTR)Lang.GetString(IuCoreUtils::Utf8ToWstring(originalText).c_str()));
#endif
return originalText;
}
示例2: GetValue
Json::Value JsonHelper::GetValue( const Json::Value& fromValue, const std::string& path, const Json::Value& defValue )
{
Json::Value node = fromValue;
int foundPosFirst = 0;
int foundPosSecond = path.find( "/" );
bool slashFound = ( foundPosSecond != std::string::npos );
while( slashFound )
{
if ( node.type() != Json::objectValue )
{
return defValue;
}
const std::string& nodeName = path.substr( foundPosFirst, foundPosSecond - foundPosFirst );
node = node.get( nodeName.c_str(), Json::nullValue );
foundPosFirst = foundPosSecond + 1;
foundPosSecond = path.find( "/", foundPosFirst );
slashFound = ( foundPosSecond != std::string::npos );
}
if ( node.type() != Json::objectValue )
{
return defValue;
}
const std::string& nodeName2 = path.substr( foundPosFirst, path.length() - foundPosFirst );
node = node.get( nodeName2.c_str(), Json::nullValue );
if ( node.isNull() )
{
return defValue;
}
else
{
return node;
}
};
示例3: 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;
}
示例4: GetJsonInt
int GetJsonInt(const Json::Value& _jsValue)
{
if ( _jsValue.type() == Json::intValue)
return _jsValue.asInt();
else if (_jsValue.type() == Json::stringValue)
return atoi(_jsValue.asCString());
else if (_jsValue.isBool())
return (int)_jsValue.asBool();
return 0;
}
示例5: make_rpc_req
Json::Value make_rpc_req(Json::Value query, bool logit,unsigned char host,int timeout)
{
HTTPClient cl;
cl.rh["Authorization"] = hosts[host].aut;
cl.rh["Connection"] = "close";
Json::FastWriter writer;
cl.pr["_full_post"] = writer.write(query);
if (logit) {
FILE *fd = fopen(".rpc.log", "w"); // log only 1 transaction
if (fd) {
fprintf(fd, "COMPLETE RPC REQUEST:\n%s\nEND OF REQUEST\n", cl.pr["_full_post"].c_str());
fclose(fd);
}
}
if(timeout){
signal(SIGALRM,connect_alarm);
alarm(timeout);
cl.request(hosts[host].url,true);
alarm(0);}
else{
cl.request(hosts[host].url,true);}
if (!cl.isOK()) {
return Json::Value();
}
std::string ans;
while (cl.peek() != EOF) {
unsigned to_r = cl.rdbuf()->in_avail();
if (to_r == 0) break;
if (to_r > 4000) to_r = 4000;
char tbuf[to_r+2];
cl.read(tbuf,to_r);
ans += std::string(tbuf, to_r);
}
if (logit) {
FILE *fd = fopen(".rpc.log", "a");
if (fd) {
fprintf(fd, "COMPLETE RPC ANSWER:\n%s\nEND OF ANSWER\n", ans.c_str());
fclose(fd);
}
}
cl.disconnect();
Json::Reader reader;
Json::Value answ;
if (!reader.parse(ans, answ)) return false;
if (answ.type() != Json::objectValue) return false;
answ = answ["result"];
if (answ.type() != Json::objectValue) return false;
return answ;
}
示例6: handleNumberOptions
static bool handleNumberOptions(const Json::Value& options, ENumberType& type, std::string& error)
{
if (options.isNull())
return true;
if (!options.isObject()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: invalid options type: %d",
options.type());
error = "Invalid options type!";
return false;
}
Json::Value tv = options["type"];
if (tv.isNull()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: No type found!");
error = "No type found!";
return false;
}
if (!tv.isString()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: Invalid type type: %d",
tv.type());
error = "Invalid type type!";
return false;
}
std::string tstr = tv.asString();
if (tstr.empty()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: Empty type!");
error = "Empty type!";
return false;
}
if (tstr == "currency") {
type = kNumberCurrency;
} else if (tstr == "percent") {
type = kNumberPercent;
} else if (tstr == "decimal") {
type = kNumberDecimal;
} else {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: unsupported type: %s",
tstr.c_str());
error = "Unsupported type!";
return false;
}
return true;
}
示例7: parseTransformation
Matrix4 FileParser::parseTransformation(const Json::Value& transformNode) const {
Matrix4 matrix = identity();
if (transformNode.type() != Json::arrayValue) {
throw RenderException("transform node must be array");
}
for (unsigned int i = 0; i < transformNode.size(); i++) {
if (transformNode[i]["scale"] != Json::nullValue) {
Json::Value node = transformNode[i]["scale"];
matrix = scale(node[(Json::Value::UInt)0].asDouble(),
node[1].asDouble(), node[2].asDouble()) * matrix;
} else if (transformNode[i]["rotateX"] != Json::nullValue) {
matrix = rotate(X, deg2rad(parseDouble(transformNode[i]["rotateX"], "rotateX"))) * matrix;
} else if (transformNode[i]["rotateY"] != Json::nullValue) {
matrix = rotate(Y, deg2rad(parseDouble(transformNode[i]["rotateY"], "rotateY"))) * matrix;
} else if (transformNode[i]["rotateZ"] != Json::nullValue) {
matrix = rotate(Z, deg2rad(parseDouble(transformNode[i]["rotateZ"], "rotateZ"))) * matrix;
} else if (transformNode[i]["translate"] != Json::nullValue) {
Json::Value node = transformNode[i]["translate"];
matrix = translate(node[(Json::Value::UInt)0].asDouble(), node[1].asDouble(), node[2].asDouble()) * matrix;
} else {
throw RenderException("unrecognized scene transformation");
}
}
return matrix;
}
示例8: GetUpcomingRecordings
/**
* \brief Fetch the list of upcoming recordings
*/
int GetUpcomingRecordings(Json::Value& response)
{
int retval = -1;
XBMC->Log(LOG_DEBUG, "GetUpcomingRecordings");
// http://madcat:49943/ArgusTV/Control/UpcomingRecordings/7?includeCancelled=true
retval = ArgusTVJSONRPC("ArgusTV/Control/UpcomingRecordings/7?includeActive=true", "", response);
if(retval >= 0)
{
if( response.type() == Json::arrayValue)
{
int size = response.size();
return size;
}
else
{
XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
return -1;
}
}
else
{
XBMC->Log(LOG_DEBUG, "GetUpcomingRecordings failed. Return value: %i\n", retval);
}
return retval;
}
示例9: GetUpcomingRecordingsForSchedule
/**
* \brief Get the upcoming recordings for a given schedule
*/
int GetUpcomingRecordingsForSchedule(const std::string& scheduleid, Json::Value& response)
{
int retval = -1;
XBMC->Log(LOG_DEBUG, "GetUpcomingRecordingsForSchedule");
char command[256];
snprintf(command, 256, "ArgusTV/Control/UpcomingRecordingsForSchedule/%s?includeCancelled=true" , scheduleid.c_str());
retval = ArgusTVJSONRPC(command, "", response);
if (retval < 0)
{
XBMC->Log(LOG_DEBUG, "GetUpcomingRecordingsForSchedule failed. Return value: %i\n", retval);
}
else
{
if( response.type() == Json::arrayValue)
{
int size = response.size();
return size;
}
else
{
XBMC->Log(LOG_DEBUG, "Unknown response format %d. Expected Json::arrayValue\n", response.type());
return -1;
}
}
return retval;
}
示例10: set
void Object::set (std::string const& k, Json::Value const& v)
{
auto t = v.type();
switch (t)
{
case Json::nullValue:
return set (k, nullptr);
case Json::intValue:
return set (k, v.asInt());
case Json::uintValue:
return set (k, v.asUInt());
case Json::realValue:
return set (k, v.asDouble());
case Json::stringValue:
return set (k, v.asString());
case Json::booleanValue:
return set (k, v.asBool());
case Json::objectValue:
{
auto object = setObject (k);
copyFrom (object, v);
return;
}
case Json::arrayValue:
{
auto array = setArray (k);
for (auto& item: v)
array.append (item);
return;
}
}
assert (false); // Can't get here.
}
示例11: setProperties
/** Set the ordered list of properties by a json value collection
*
* @param jsonValue :: The jsonValue of property values
* @param ignoreProperties :: A set of names of any properties NOT to set
* from the propertiesArray
* @param targetPropertyManager :: the propertymanager to make the changes to,
* most of the time this will be *this
*/
void PropertyManager::setProperties(
const ::Json::Value &jsonValue, IPropertyManager *targetPropertyManager,
const std::set<std::string> &ignoreProperties) {
if (jsonValue.type() == ::Json::ValueType::objectValue) {
// Some algorithms require Filename to be set first do that here
const std::string propFilename = "Filename";
::Json::Value filenameValue = jsonValue[propFilename];
if (!filenameValue.isNull()) {
const std::string value = jsonValue[propFilename].asString();
// Set it
targetPropertyManager->setPropertyValue(propFilename, value);
}
for (::Json::ArrayIndex i = 0; i < jsonValue.size(); i++) {
const std::string propName = jsonValue.getMemberNames()[i];
if ((propFilename != propName) &&
(ignoreProperties.find(propName) == ignoreProperties.end())) {
::Json::Value propValue = jsonValue[propName];
const std::string value = propValue.asString();
// Set it
targetPropertyManager->setPropertyValue(propName, value);
}
}
}
}
示例12: RequestGuideChannelList
/*
* \brief Retrieve the TV channels that are in the guide
*/
int RequestGuideChannelList()
{
Json::Value root;
int retval = E_FAILED;
retval = ForTheRecordJSONRPC("ForTheRecord/Guide/Channels/Television", "", root);
if(retval >= 0)
{
if( root.type() == Json::arrayValue)
{
int size = root.size();
// parse channel list
for ( int index =0; index < size; ++index )
{
std::string name = root[index]["Name"].asString();
XBMC->Log(LOG_DEBUG, "Found channel %i: %s\n", index, name.c_str());
}
return size;
}
else
{
XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
return -1;
}
}
else
{
XBMC->Log(LOG_DEBUG, "RequestChannelList failed. Return value: %i\n", retval);
}
return retval;
}
示例13: RequestChannelGroupMembers
/*
* \brief Get the list with channels for the given channel group from 4TR
* \param channelGroupId GUID of the channel group
*/
int RequestChannelGroupMembers(const std::string& channelGroupId, Json::Value& response)
{
int retval = -1;
std::string command = "ForTheRecord/Scheduler/ChannelsInGroup/" + channelGroupId;
retval = ForTheRecordJSONRPC(command, "", response);
if(retval >= 0)
{
if( response.type() == Json::arrayValue)
{
int size = response.size();
return size;
}
else
{
XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
return -1;
}
}
else
{
XBMC->Log(LOG_ERROR, "RequestChannelGroupMembers failed. Return value: %i\n", retval);
}
return retval;
}
示例14: GetRecordingsForTitleUsingURL
int GetRecordingsForTitleUsingURL(const std::string& title, Json::Value& response)
{
int retval = E_FAILED;
XBMC->Log(LOG_DEBUG, "GetRecordingsForTitleUsingURL");
CURL *curl;
curl = curl_easy_init();
if(curl)
{
std::string command = "ForTheRecord/Control/RecordingsForProgramTitle/Television/";
char* pch = curl_easy_escape(curl, title.c_str(), 0);
command += pch;
curl_free(pch);
retval = ForTheRecord::ForTheRecordJSONRPC(command, "?includeNonExisting=false", response);
if(retval >= 0)
{
if (response.type() != Json::arrayValue)
{
retval = E_FAILED;
XBMC->Log(LOG_NOTICE, "GetRecordingsForTitleUsingURL did not return a Json::arrayValue [%d].", response.type());
}
}
else
{
XBMC->Log(LOG_NOTICE, "GetRecordingsForTitleUsingURL remote call failed.");
}
curl_easy_cleanup(curl);
}
return retval;
}
示例15: GetUpcomingProgramsForSchedule
/**
* \brief Get the upcoming programs for a given schedule
*/
int GetUpcomingProgramsForSchedule(const Json::Value& schedule, Json::Value& response)
{
int retval = -1;
XBMC->Log(LOG_DEBUG, "GetUpcomingProgramsForSchedule");
char arguments[1024];
Json::FastWriter writer;
snprintf( arguments, sizeof(arguments), "{\"IncludeCancelled\":true,\"Schedule\":%s}", writer.write(schedule).c_str());
retval = ForTheRecordJSONRPC("ForTheRecord/Scheduler/UpcomingProgramsForSchedule", arguments, response);
if(retval >= 0)
{
if( response.type() == Json::arrayValue)
{
int size = response.size();
return size;
}
else
{
XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
return -1;
}
}
else
{
XBMC->Log(LOG_DEBUG, "GetUpcomingProgramsForSchedule failed. Return value: %i\n", retval);
}
return retval;
}