本文整理汇总了C++中json::Value::asUInt方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::asUInt方法的具体用法?C++ Value::asUInt怎么用?C++ Value::asUInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::asUInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filmonAPIlogin
// Login subscriber
bool filmonAPIlogin(std::string username, std::string password) {
bool res = filmonAPIgetSessionKey();
if (res) {
XBMC->Log(LOG_DEBUG, "logging in user");
filmonUsername = username;
filmonpassword = password;
std::string md5pwd = PVRXBMC::XBMC_MD5::GetMD5(password);
std::transform(md5pwd.begin(), md5pwd.end(), md5pwd.begin(), ::tolower);
std::string params = "login=" + username + "&password=" + md5pwd;
res = filmonRequest("tv/api/login", sessionKeyParam + "&" + params, 1);
if (res) {
Json::Value root;
Json::Reader reader;
reader.parse(response, root);
// Favorite channels
channelList.clear();
Json::Value favouriteChannels = root["favorite-channels"];
unsigned int channelCount = favouriteChannels.size();
for (unsigned int channel = 0; channel < channelCount; channel++) {
Json::Value chId = favouriteChannels[channel]["channel"]["id"];
channelList.push_back(chId.asUInt());
XBMC->Log(LOG_INFO, "added channel %u",
chId.asUInt());
}
clearResponse();
}
}
return res;
}
示例2: setDelta
void deltaTimeInfo::setDelta(const Json::Value& params)
{
uint32_t samples = 1;
uint32_t seconds = 0;
uint32_t fraction = 0;
uint32_t subFraction = 0;
Json::Value value;
value = params["samples"];
if(value.isNull()==false) {
samples = value.asUInt();
if(samples==0) {
throw std::runtime_error("samples must be > 0");
}
}
const Json::Value& timeObject = params["delta"];
if(timeObject["type"]=="ntp") {
value = timeObject["seconds"];
if(value.isNull()==false) {
seconds = value.asUInt();
}
value = timeObject["fraction"];
if(value.isNull()==false) {
fraction = value.asUInt();
}
value = timeObject["subFraction"];
if(value.isNull()==false) {
subFraction = value.asUInt();
}
}
uint64_t ntpTimestamp = seconds;
ntpTimestamp <<= 32;
ntpTimestamp |= fraction;
// we are loosing precision here. In order to compensate this, we calculate a correction to use.
m_deltaNtpTimestamp = ntpTimestamp/samples;
m_deltaSubFraction = subFraction/samples;
// determine remainder and calculate sub fraction from it.
uint64_t rest = m_deltaNtpTimestamp%samples;
rest <<= 32;
rest /= samples;
m_deltaSubFraction += static_cast < uint32_t > (rest & 0xffffffff);
std::cout << __FUNCTION__ << std::endl;
std::cout << "seconds = " << seconds << std::hex << " (0x" << seconds << ")" << std::endl;
std::cout << "fraction = " << fraction << std::hex << " (0x" << fraction << ")" << std::endl;
std::cout << "subFraction = " << subFraction << std::hex << " (0x" << subFraction << ")" << std::endl;
}
示例3: AssignKeyValue
void Attachment::AssignKeyValue(const std::string &key, const Json::Value &val) {
if(key == std::string("content_type")) {
content_type = val.asString();
return;
}
if(key == std::string("category")) {
category = val.asString();
return;
}
if(key == std::string("name")) {
name = val.asString();
return;
}
if(key == std::string("size")) {
size = val.asUInt();
return;
}
if(key == "hash") {
hash = val.asString();
return;
}
if(key == "digest") {
digest = val.asString();
return;
}
}
示例4: ToBool
bool JsonHelper::ToBool( const Json::Value& value, bool defaultResult )
{
if ( value.isBool() )
{
return value.asBool();
}
if ( value.isInt() )
{
return (bool)value.asInt();
}
if ( value.isDouble() )
{
return (bool)value.asDouble();
}
if ( value.isUInt() )
{
return (bool)value.asUInt();
}
if ( value.isString() )
{
const std::string& str = value.asString();
return ( str == "true" || str == "1" );
}
return defaultResult;
}
示例5: jsonValueToVariant
FB::variant jsonValueToVariant( Json::Value root )
{
Json::Value def;
if (root.isString())
return root.asString();
else if (root.isBool())
return root.asBool();
else if (root.isDouble())
return root.asDouble();
else if (root.isInt())
return root.asInt();
else if (root.isUInt())
return root.asUInt();
else if (root.isNull())
return FB::FBNull();
else if (root.isArray()) {
FB::VariantList outList;
for (size_t i = 0; i < root.size(); ++i) {
outList.push_back(jsonValueToVariant(root.get(i, def)));
}
return outList;
} else if (root.isObject()) {
Json::Value::Members members = root.getMemberNames();
FB::VariantMap outMap;
for (Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)
{
outMap[*it] = jsonValueToVariant(root.get(*it, def));
}
return outMap;
} else {
return FB::FBVoid();
}
}
示例6: 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.
}
示例7: addField
void _PlanOperation::addField(const Json::Value &field) {
if (field.isNumeric()) {
addField(field.asUInt());
} else if (field.isString()) {
addNamedField(field.asString());
} else throw std::runtime_error("Can't parse field name, neither numeric nor std::string");
}
示例8: parseFromJsonToDictionary
/// 从 Json 解析数据到 dictNode 中
static void parseFromJsonToDictionary(const Json::Value & jsonNode, CCDictionary * dictNode)
{
Json::Value::Members members = jsonNode.getMemberNames();
for (Json::Value::Members::iterator beg = members.begin(); beg != members.end(); ++beg)
{
std::string name = *beg;
Json::Value child = jsonNode[name];
if (child.isArray())
{
CCArray * arr = CCArray::create();
parseFromJsonToArray(child, arr);
dictNode->setObject(arr, name);
}
else if (child.isObject())
{
CCDictionary * dict = CCDictionary::create();
parseFromJsonToDictionary(child, dict);
dictNode->setObject(dict, name);
}
else if (child.isString())
{
CCString * str = CCString::createWithFormat("%s", child.asCString());
dictNode->setObject(str, name);
}
else if (child.isInt())
{
CCString * str = CCString::createWithFormat("%d", child.asInt());
dictNode->setObject(str, name);
}
else if (child.isUInt())
{
CCString * str = CCString::createWithFormat("%u", child.asUInt());
dictNode->setObject(str, name);
}
else if (child.isInt64())
{
CCString * str = CCString::createWithFormat("%lld", child.asInt64());
dictNode->setObject(str, name);
}
else if (child.isUInt64())
{
CCString * str = CCString::createWithFormat("%llu", child.asUInt64());
dictNode->setObject(str, name);
}
else if (child.isDouble())
{
CCString * str = CCString::createWithFormat("%f", child.asDouble());
dictNode->setObject(str, name);
}
else if (child.isBool())
{
CCString * str = CCString::createWithFormat("%d", child.asInt());
dictNode->setObject(str, name);
}
}
}
示例9: init
void JsonTree::init( const string &key, const Json::Value &value, bool setType, NodeType nodeType, ValueType valueType )
{
mKey = key;
mNodeType = nodeType;
mParent = 0;
mValue = "";
mValueType = valueType;
if( ! value.isNull() && ( value.isArray() || value.isObject() ) ) {
if( value.isArray() ) {
mNodeType = NODE_ARRAY;
for ( uint32_t i = 0; i < value.size(); i++ ) {
pushBack( JsonTree( "", value[ i ] ) );
}
}
else if( value.isObject() ) {
mNodeType = NODE_OBJECT;
Json::Value::Members members = value.getMemberNames();
for( Json::Value::Members::const_iterator memberIt = members.begin(); memberIt != members.end(); ++memberIt ) {
string key = *memberIt;
pushBack( JsonTree( key, value[ key ] ) );
}
}
}
else {
if( value.isBool() ) {
mValue = toString( value.asBool() );
if( setType ) {
mValueType = VALUE_BOOL;
}
}
else if ( value.isDouble() ) {
mValue = toString( value.asDouble() );
if ( setType ) {
mValueType = VALUE_DOUBLE;
}
}
else if ( value.isInt() ) {
mValue = toString( value.asInt() );
if ( setType ) {
mValueType = VALUE_INT;
}
}
else if ( value.isString() ) {
mValue = toString( value.asString() );
if ( setType ) {
mValueType = VALUE_STRING;
}
}
else if ( value.isUInt() ) {
mValue = toString( value.asUInt() );
if ( setType ) {
mValueType = VALUE_UINT;
}
}
}
}
示例10: GetUInt32
bool GetUInt32(const Json::Value& value, uint32_t* out) {
if (value.isNull()) {
return false;
}
if (!(value.isInt() || value.isUInt())) {
return false;
}
*out = value.asUInt();
return true;
}
示例11:
void Deserialize_UInt32( const Json::Value& srcValue, UINT32 &dstValue )
{
//HACK: Json Cpp saves small unsigned integers as signed ints
if( srcValue.isInt() )
{
const Json::Int signedIntValue = srcValue.asInt();
if( signedIntValue >= Json::Value::minInt
&& signedIntValue <= Json::Value::maxInt )
{
dstValue = signedIntValue;
return;
}
}
CHK_VRET_IF_NOT( srcValue.isUInt() );
Assert( srcValue.asUInt() < MAX_UINT32 );
dstValue = srcValue.asUInt();
}
示例12: switch
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
switch ( value.type() )
{
case Json::nullValue:
fprintf( fout, "%s=null\n", path.c_str() );
break;
case Json::intValue:
fprintf( fout, "%s=%ld\n", path.c_str(), value.asInt() );
break;
case Json::uintValue:
fprintf( fout, "%s=%lu\n", path.c_str(), value.asUInt() );
break;
case Json::realValue:
fprintf( fout, "%s=%.16g\n", path.c_str(), value.asDouble() );
break;
case Json::stringValue:
fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
break;
case Json::booleanValue:
fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
break;
case Json::arrayValue:
{
fprintf( fout, "%s=[]\n", path.c_str() );
int size = value.size();
for ( int index =0; index < size; ++index )
{
static char buffer[16];
sprintf( buffer, "[%d]", index );
printValueTree( fout, value[index], path + buffer );
}
}
break;
case Json::objectValue:
{
fprintf( fout, "%s={}\n", path.c_str() );
Json::Value::Members members( value.getMemberNames() );
std::sort( members.begin(), members.end() );
std::string suffix = *(path.end()-1) == '.' ? "" : ".";
for ( Json::Value::Members::iterator it = members.begin();
it != members.end();
++it )
{
const std::string &name = *it;
printValueTree( fout, value[name], path + suffix + name );
}
}
break;
default:
break;
}
}
示例13:
k8s_container::list k8s_component::extract_pod_containers(const Json::Value& item)
{
k8s_container::list ext_containers;
Json::Value spec = item["spec"];
if(!spec.isNull())
{
Json::Value containers = spec["containers"];
if(!containers.isNull())
{
for (auto& container : containers)
{
std::string cont_name;
Json::Value name = container["name"];
if(!name.isNull()) { cont_name = name.asString(); }
else { return ext_containers; }
k8s_container::port_list cont_ports;
Json::Value ports = container["ports"];
for(const auto& port : ports)
{
k8s_container::port cont_port;
Json::Value name = port["name"];
if(!name.isNull())
{
cont_port.set_name(name.asString());
}
Json::Value cport = port["containerPort"];
if(!cport.isNull())
{
cont_port.set_port(cport.asUInt());
}
else
{
g_logger.log("Port not found, setting value to 0", sinsp_logger::SEV_WARNING);
cont_port.set_port(0);
}
Json::Value protocol = port["protocol"];
if(!protocol.isNull())
{
cont_port.set_protocol(protocol.asString());
}
else
{
std::string port_name = name.isNull() ? "[NO NAME]" : name.asString();
g_logger.log("Protocol not found for port: " + port_name, sinsp_logger::SEV_WARNING);
}
cont_ports.push_back(cont_port);
}
ext_containers.emplace_back(k8s_container(cont_name, cont_ports));
}
}
}
return ext_containers;
}
示例14: Deserialize
bool Deserialize ( const Json::Value& json_val, unsigned int& obj_val )
{
/**
* Warning: the default type may be int, even you Serialize a uint value
*/
if ( json_val.isIntegral () )
{
obj_val = json_val.asUInt ();
return true;
}
return false;
}
示例15: filmonAPIlogin
// Login subscriber
bool filmonAPIlogin(std::string username, std::string password) {
bool res = filmonAPIgetSessionKey();
if (res) {
std::cerr << "FilmonAPI: logging in user" << std::endl;
filmonUsername = username;
filmonpassword = password;
// Password is MD5 hex
CryptoPP::Weak1::MD5 hash;
byte digest[CryptoPP::Weak1::MD5::DIGESTSIZE];
hash.CalculateDigest(digest, (byte*) password.c_str(),
password.length());
CryptoPP::HexEncoder encoder;
std::string md5pwd;
encoder.Attach(new CryptoPP::StringSink(md5pwd));
encoder.Put(digest, sizeof(digest));
encoder.MessageEnd();
toLowerCase(md5pwd);
std::string params = "login=" + username + "&password=" + md5pwd;
res = filmonRequest("tv/api/login", sessionKeyParam + "&" + params);
if (res) {
Json::Value root;
Json::Reader reader;
reader.parse(&response.memory[0],
&response.memory[(long) response.size - 1], root);
// Favorite channels
channelList.clear();
Json::Value favouriteChannels = root["favorite-channels"];
unsigned int channelCount = favouriteChannels.size();
for (unsigned int channel = 0; channel < channelCount; channel++) {
Json::Value chId = favouriteChannels[channel]["channel"]["id"];
channelList.push_back(chId.asUInt());
std::cerr << "FilmonAPI: added channel " << chId.asUInt()
<< std::endl;
}
clearResponse();
}
}
return res;
}