Exemplo n.º 1
0
 static void add(
     MetadataNode&      parent,
     const std::string& name,
     const Json::Value& node
 )
 {
     if      (node.isNull())   { parent.add(name, ""); }
     else if (node.isBool())   { parent.add(name, node.asBool()); }
     else if (node.isInt())    { parent.add(name, node.asInt64()); }
     else if (node.isUInt())   { parent.add(name, node.asUInt64()); }
     else if (node.isDouble()) { parent.add(name, node.asDouble()); }
     else if (node.isString()) { parent.add(name, node.asString()); }
     else if (node.isObject())
     {
         MetadataNode object = parent.add(name);
         for (const std::string& name: node.getMemberNames())
         {
             add(object, name, node[name]);
         }
     }
     else if (node.isArray())
     {
         for (const Json::Value& item: node)
         {
             add(parent, name, item);
         }
     }
 }
Exemplo n.º 2
0
	Value convert_json(const Json::Value &val)
	{
		using namespace Json;
		switch (val.type())
		{
		case nullValue:
			return Nil;
		case intValue:
			return value(val.asInt64());
		case uintValue:
			return value((int64_t)val.asUInt64());
		case realValue:
			return value(val.asDouble());
		case stringValue:
			return value(val.asString());
		case booleanValue:
			return bvalue(val.asBool());
		case arrayValue:
			return convert_json_array(val);
		case objectValue:
			return convert_json_complex(val);
		default:
			throw loader_error("Invalid value encountered while parsing json");
		}
	}
Exemplo n.º 3
0
		AnyValue JsonSerializer::toAny(const Json::Value & val)
		{
			std::vector<AnyValue> arr;
			Bundle b;
			switch (val.type())
			{
			case Json::ValueType::arrayValue:
				for (auto e : val) arr.push_back(this->toAny(e));
				return arr;
			case Json::ValueType::booleanValue:
				return val.asBool();
			case Json::ValueType::intValue:
				return (int64_t)val.asInt64();
			case Json::ValueType::nullValue:
				return nullptr;
			case Json::ValueType::objectValue:
				for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
				{
					std::string name = it.name();
					b.set(name, this->toAny(*it));
				}
				return b;
			case Json::ValueType::realValue:
				return val.asDouble();
			case Json::ValueType::stringValue:
				return val.asString();
			case Json::ValueType::uintValue:
				return (uint64_t)val.asUInt64();
			}
			return AnyValue();
		}
Exemplo n.º 4
0
            // Read a natural 
            Natural natural(
                Optizelle::Messaging const & msg,
                Json::Value const & json,
                std::string const & name
            ) {
                // Set the error message
                std::string const err_msg = "Invalid JSON parameter: "
                    + name + " contains an invalid natural.";

                // As long as we have an unsigned integer, grab it
                if(json.isUInt())
                    return Natural(Json::Value::UInt64(json.asUInt64()));
                
                // If we have an integer, grab it if it's positive
                else if(json.isInt()) {
                    Integer val(json.asInt64());
                    if(val>=0)
                        return Natural(val);
                    else
                        msg.error(err_msg);

                // Anything else is an error
                } else
                    msg.error(err_msg);

                // We should not hit this point
                throw;
            }
 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;
         }
     }
 }
Exemplo n.º 6
0
/// 从 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);
		}
	}
}
Exemplo n.º 7
0
 bool Deserialize ( const Json::Value& json_val, json_lib::uint64& obj_val )
 {
     if ( json_val.isIntegral () )
     {
         obj_val = json_val.asUInt64 ();
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
    unsigned long JsonUtils::asUnsignedLong(const Json::Value &value, long unsigned int defaultValue)
    {
        long unsigned int returned = defaultValue;

        if(value.isString())
            returned = Ogre::StringConverter::parseUnsignedLong(value.asString(), defaultValue);

        if(value.isIntegral())
            returned = value.asUInt64();

        return returned;
    }
Exemplo n.º 9
0
event_manager::time_point core::time_point_from_json(const Json::Value& value)
{
	const auto param = value.asUInt64();
	const auto duration = event_manager::time_point::duration(param);
	return event_manager::time_point(duration);
}
Exemplo n.º 10
0
template<> ZEROBUF_INL uint64_t fromJSON( const Json::Value& json )
    { return json.asUInt64(); }
Exemplo n.º 11
0
void cmnDataJSON<unsigned long long int>::DeSerializeText(DataType & data, const Json::Value & jsonValue) throw (std::runtime_error) {
    data = jsonValue.asUInt64();
}
Exemplo n.º 12
0
	uint64_t jsonNodeAs<uint64_t>(const Json::Value& node) {
		if (node.isNull()) {
			return 0;
		}
		return node.asUInt64();
	}
Exemplo n.º 13
0
    int ToPbSingle(const Json::Value &value, const FieldDescriptor *pFieldDescriptor, Message &message, map<string, string>& key_map)
    {
        if (!check_type(value.type(), pFieldDescriptor->cpp_type()))
        {
            return 1;
        }

        const Reflection *pReflection = message.GetReflection();
        EnumDescriptor      *pEnumDes = NULL;
        EnumValueDescriptor *pEnumValueDes = NULL;
        int ret = 0;
        switch(pFieldDescriptor->cpp_type())
        {
            case FieldDescriptor::CPPTYPE_INT32:
            {
                pReflection->SetInt32(&message, pFieldDescriptor, value.asInt());
                break;
            }
            case FieldDescriptor::CPPTYPE_UINT32:
            {
                pReflection->SetUInt32(&message, pFieldDescriptor, value.asUInt());
                break;
            }
            case FieldDescriptor::CPPTYPE_INT64:
            {
                pReflection->SetInt64(&message, pFieldDescriptor, value.asInt64());
                break;
            }
            case FieldDescriptor::CPPTYPE_UINT64:
            {
                pReflection->SetUInt64(&message, pFieldDescriptor, value.asUInt64());
                break;
            }
            case FieldDescriptor::CPPTYPE_STRING:
            {
                pReflection->SetString(&message, pFieldDescriptor, value.asString());
                break;
            }
            case FieldDescriptor::CPPTYPE_BOOL:
            {
                pReflection->SetBool(&message, pFieldDescriptor, value.asBool());
                break;
            }
            case FieldDescriptor::CPPTYPE_DOUBLE:
            {
                pReflection->SetDouble(&message, pFieldDescriptor, value.asDouble());
                break;
            }
            case FieldDescriptor::CPPTYPE_FLOAT:
            {
                pReflection->SetFloat(&message, pFieldDescriptor, value.asFloat());
                break;
            }
            case FieldDescriptor::CPPTYPE_ENUM:
            {
                if ((pEnumDes = (EnumDescriptor *)pFieldDescriptor->enum_type()) == NULL)
                {
                    return 1;
                }

                if ((pEnumValueDes = (EnumValueDescriptor *)pEnumDes->FindValueByNumber(value.asInt())) == NULL)
                {
                    return 1;
                }

                pReflection->SetEnum(&message, pFieldDescriptor, pEnumValueDes);
                break;
            }
            case FieldDescriptor::CPPTYPE_MESSAGE:
            {
                Message *pmessage = pReflection->MutableMessage(&message, pFieldDescriptor);
                if (key_map.size() == 0)
                {
                    ret = ToPb(*pmessage, value);
                }
                else
                {
                    ret = ToPbMap(*pmessage, value, key_map);
                }

                break;
            }
            default:
            {
                ret = 1;
                break;
            }
        }

        return ret;
    }