当前位置: 首页>>代码示例>>C++>>正文


C++ Value::asString方法代码示例

本文整理汇总了C++中json::Value::asString方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::asString方法的具体用法?C++ Value::asString怎么用?C++ Value::asString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在json::Value的用法示例。


在下文中一共展示了Value::asString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

Entity *EntityResourceManager::loadType(Json::Value &root)
{
	Json::Value entityType;
	entityType = root.get("type", NULL);
	if(entityType == NULL)
	{
		return NULL;
	}

	Entity *entityPtr = NULL;
	
	//read from file
	std::string type = entityType.asString();
	if(type.compare("player") == 0)
	{
		entityPtr = new Player();
		entityPtr->setType(PLAYER);
	}
	else if(type.compare("enemy") == 0)
	{
		entityPtr = new Enemy();
		entityPtr->setType(ENEMY);
	}
	else if(type.compare("damaging") == 0)
	{
		entityPtr = new DamagingEntity();
		entityPtr->setType(DAMAGING_ENTITY);
	}
	else if(type.compare("wall") == 0)
	{
		entityPtr = new Wall();
		entityPtr->setType(WALL);
	}
	else
	{
		//invalid type, stop right here criminal scum
		return NULL;
	}

	//if we got to here it was a valid type
	return entityPtr;
}
开发者ID:Kerswill,项目名称:Bacterium,代码行数:42,代码来源:EntityResourceManager.cpp

示例2: ToLong

 long JsonHelper::ToLong( const Json::Value& value, long defaultResult )
 {
     if ( value.isUInt() )
     {
         return  value.asUInt();
     }
     if ( value.isInt() )
     {
         return ((long)value.asInt());
     }
     if ( value.isDouble() )
     {
         return value.asDouble();
     }
     if ( value.isString() )
     {
         return Core::Convert::ToLong( value.asString() );
     }
     return defaultResult;
 }
开发者ID:Nelar,项目名称:ice_cream_adventure_mobile,代码行数:20,代码来源:JsonHelper.cpp

示例3: Encode

int JsonCoder::Encode(char* buf, size_t len, const Message* message) const
{
    Json::Value obj;
    if(0 != message->JsonEncode(obj))
    {
        LOG_ERROR("message:[%s] jsonencode error", message->ToString().c_str());
        return -1;
    }
    obj["_msg_"] = Json::Value(message->GetTypeName().c_str());
    const std::string& data = obj.asString();
    if (data.size() > len)
    {
        LOG_ERROR("data len:%zd, buf len:%zd", data.size(), len);
        return -1;
    }
    int size = htonl(data.size()+4);
    memcpy(buf, (const char*)&size, 4);
    memcpy(buf+4, data.c_str(), data.size());
    return 4+data.size();
}
开发者ID:tuita,项目名称:DOMQ,代码行数:20,代码来源:coder.cpp

示例4: parse

void PrefabEntityParser::parse(Entity* entity, const Json::Value& node) {
  String path = node.asString();
  String fullPath = CCFileUtils::fullPathFromRelativePath(path.c_str());
  String json = String::fromFile(fullPath);
  
  Json::Reader reader;
  Json::Value root;
  
  reader.parse(json.str(), root);
  
  Json::Value::Members members = root.getMemberNames();
  
  for (int i = 0; i < members.size(); ++i) {
    shared_ptr<EntityParser> parser = EntityParser::parser(members[i]);
    Json::Value data = root[parser->type().c_str()];
    parser->parse(entity, data);
  }
  
  entity->prefabOverride();
}
开发者ID:nkostelnik,项目名称:WonderPants,代码行数:20,代码来源:PrefabEntityParser.cpp

示例5: MethodName

std::string Channel::MethodName(std::string _mode,Json::Value _method)
{
    std::string mode="";
    std::string method="";
    std::string mms=_method.asString();
    int pos = mms.find_first_of('.');
    if(std::string::npos== pos){
        LOGE("method:find error,%d",pos);
        return method;
    }
    mode = mms.erase(pos);
    if(mode == _mode){
      method = mms.erase(0,pos+1);
      LOGI("find method:%s",method.c_str());
    }
    else{
        LOGE("mode(%s) is not match mode(%s)",mode.c_str(),_mode.c_str());
    }
    return method;
}
开发者ID:BrandonHe,项目名称:hmi_sdk,代码行数:20,代码来源:Channel.cpp

示例6: string

            // Read a string 
            std::string string(
                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 + " is not a valid parameter.";

                // As long as we have an unsigned integer, grab it
                if(json.isString())
                    return json.asString();

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

                // We should not hit this point
                throw;
            }
开发者ID:Dapid,项目名称:Optizelle,代码行数:21,代码来源:json.cpp

示例7: ChangeLayout

void LCDCore::ChangeLayout() {
    if(is_transitioning_) {
        //timer_->start(100);
        return;
    }
    LCDError("ChangeLayout");
    Json::Value *t = CFG_Fetch_Raw(CFG_Get_Root(), 
        current_layout_ + ".transition");
    if(!t or transitions_off_) {
        StopLayout(current_layout_);
        StartLayout();
    } else {
        StartTransition(t->asString());
        delete t;
        if(type_ & LCD_TEXT) {
            LCDText *text = ((LCDText *)lcd_);
            text->CleanBuffer(text->LayoutFB);
        }
    }
}
开发者ID:Starlon,项目名称:FroyVisuals-old,代码行数:20,代码来源:LCDCore.cpp

示例8: decode_from_json_object

void QuestionRequest::decode_from_json_object(const Json::Value &root)
{
    Json::Value tmp;

    

    
    if ( root.isObject() && root.isMember("msg") ) {
        tmp = root["msg"];
        if ( !tmp.isNull() )
        {
            msg = tmp.asString();
        }
    }

    
    if ( root.isObject() && root.isMember("status") ) {
        tmp = root["status"];
        if ( !tmp.isNull() )
        {
            status = tmp.asInt();
        }
    }

    
    
    if ( root.isObject() && root.isMember("data") ) {
        const Json::Value &array_data = root["data"];
        if ( !array_data.isNull() )
        {
            int size = array_data.size();
            for ( int i = 0; i < size; i++ ) {
                CheckUserNameRequestQuestion item;
                item.decode_from_json_object(array_data[i]);
                data.push_back(item);
            }
        }
    }
    
    
}
开发者ID:YouLooksLikeNotDelicious,项目名称:websrv,代码行数:41,代码来源:Request.cpp

示例9:

k8s_pair_list k8s_component::extract_object(const Json::Value& object, const std::string& name)
{
	k8s_pair_list entry_list;
	if(!object.isNull())
	{
		Json::Value entries = object[name];
		if(!entries.isNull())
		{
			Json::Value::Members members = entries.getMemberNames();
			for (auto& member : members)
			{
				Json::Value val = entries[member];
				if(!val.isNull())
				{
					entry_list.emplace_back(k8s_pair_t(member, val.asString()));
				}
			}
		}
	}
	return entry_list;
}
开发者ID:PerthCharles,项目名称:sysdig,代码行数:21,代码来源:k8s_component.cpp

示例10: Update_ExistentUserChecked

string UserHandler::Update_ExistentUserChecked(string identifier, Json::Value rootToken, string json, User user){
	if(Token::IsGuidValid(identifier, rootToken.asString())){
		std::set<string> ignoredAttributes;
		ignoredAttributes.insert("identifier");
		ignoredAttributes.insert("md5");
		ignoredAttributes.insert("root");
		ignoredAttributes.insert("quotaLimitMB");
		ignoredAttributes.insert("isActive");

		user.SetAllAttributes(json, ignoredAttributes);

		user.Save();

		Log::insert(Log::TYPE_INFORMATION, "Actualizado exitosamente el usuario " + identifier);
		return "{ \"result\" : \"OK\" ,  \"message\" : \"\" }";
	}
	else{
		Log::insert(Log::TYPE_ERROR, "Error en la actualización del usuario " + identifier + ". Token inválido.");
		return "{ \"result\" : \"ERROR\" ,  \"message\" : \"Invalid token\" }";
	}
}
开发者ID:pabloalbanese,项目名称:taller2,代码行数:21,代码来源:UserHandler.cpp

示例11: resolvePossibleRef

 Json::Value resolvePossibleRef(Json::Value const &input,
                                bool stringAcceptableResult,
                                std::vector<std::string> const &searchPath) {
     Json::Value ret{Json::nullValue};
     if (input.isString()) {
         ret = loadFromFile(input.asString(), searchPath);
         if (ret.isNull() && stringAcceptableResult) {
             ret = input;
         }
         return ret;
     }
     if (input.isObject() && input.isMember("$ref")) {
         /// @todo remove things after the filename in the ref.
         ret = loadFromFile(input["$ref"].asString(), searchPath);
         if (!ret.isNull()) {
             return ret;
         }
     }
     ret = input;
     return ret;
 }
开发者ID:bwrsandman,项目名称:OSVR-Core,代码行数:21,代码来源:JSONResolvePossibleRef.cpp

示例12: ParseGameBoardStateMessage

State const* MessageFactory::ParseGameBoardStateMessage(Json::Value const& root) const {
    int sequence = root.get("sequence", -1).asInt();
    double timestamp = root.get("timestamp", 0.0).asDouble();
    Json::Value states = root.get("states", "not found");

    Json::Value mine = states.get(USERNAME, "not found");
    int piece = mine.get("piece_number", -1).asInt();
    Json::Value boardV = mine.get("board_state", "0");
    if (boardV.asString().size() != BOARD_DESC_SIZE) {
        return new ErrorState("Invalid board description.");
    }
    char* board = new char[BOARD_DESC_SIZE];
    memcpy((void*)board, (void*)boardV.asCString(), BOARD_DESC_SIZE);
    Json::Value clearedV = mine.get("cleared_rows", "not found");
    std::vector<int>* cleared = new std::vector<int>();
    for (unsigned i = 0; i < clearedV.size(); ++i) {
        cleared->push_back(clearedV[i].asInt());
    }

    return new GameBoardState(sequence, timestamp, board, piece, cleared);
}
开发者ID:ahelwer,项目名称:pason2012,代码行数:21,代码来源:message_factory.cpp

示例13: pushValue

 void LuaModule::pushValue(const Json::Value &val, lua_State * stack) {
     if (val.isIntegral()) {
         lua_pushinteger(stack, val.asInt());
     } else if (val.isDouble()) {
         lua_pushnumber(stack, val.asDouble());
     } else if (val.isBool()) {
         lua_pushboolean(stack, val.asBool());
     } else if (val.isString()) {
         lua_pushstring(stack, val.asString().c_str());
     } else if (val.isNull()) {
         //lua_pushstring(stack, val.asString().c_str());
         lua_pushnil(stack);
     } else {
         lua_pop(stack, 1);
         std::stringstream ss;
         ss << val.type();
         std::string typeNum;
         ss >> typeNum;
         throw std::runtime_error("Value type error: value of type " + typeNum);
     }
 }
开发者ID:achernakov,项目名称:flugegeheimen,代码行数:21,代码来源:LuaModule.cpp

示例14: _Deserialize

	void _Deserialize(const AuthorizedObject &parent_obj, const Json::Value &json)
	{
		if(!json.isConvertibleTo(Json::stringValue))
			throw UnexpectedException("!json.isConvertibleTo(Json::stringValue)");

		const std::string &str = json.asString();

		bool found = false;

		// Hack: This is nasty, but required to do a complete iteration. Hopefully, we never have to go over the int limit!
		for(int s = (int)none; s < (int)count; ++s)
		{
			if(stricmp(str.c_str(), str_array[s]) == 0)
			{
				t_ = (T)s;
				break;
			}
		}

		if(!found)
			throw UnexpectedException("!found");
	}
开发者ID:kemcoi,项目名称:libfacebookcpp,代码行数:22,代码来源:Enum.hpp

示例15: serialisePointer

//////////////////////////////////////////////////////////////////////////
// serialisePointer
//virtual
Json::Value SeJsonWriter::serialisePointer( void* pData, const ReClass* pClass, BcU32 ParentFlags )
{
	if( pData != nullptr )
	{
		// Setup Json::Value for this class.
		Json::Value PointerValue = ObjectCodec_->serialiseAsStringRef( pData, pClass );
	
		// Check if we can up cast.
		if( pClass->hasBaseClass( ReObject::StaticGetClass() ) )
		{
			ReObject* Object = reinterpret_cast< ReObject* >( pData );
			pClass = Object->getClass();
		}
			
		// Add to list to serialise if it hasn't been added.
		if( ObjectCodec_->shouldSerialiseContents( pData, pClass ) )
		{
			if( ( ParentFlags & bcRFF_OWNER ) == 0 )
			{
				auto ClassToSerialise = SerialiseClass( pData, pClass );
				if( std::find( SerialiseClasses_.begin(), SerialiseClasses_.end(), ClassToSerialise ) == SerialiseClasses_.end() )
				{
					SerialiseClasses_.push_back( ClassToSerialise );
				}
			}
			else
			{	
				auto ClassValue = serialiseClass( pData, pClass, 0, true );
				ObjectValueMap_[ PointerValue.asString() ] = ClassValue;
			}
		}

		return PointerValue;
	}

	return Json::nullValue;
}
开发者ID:Psybrus,项目名称:Psybrus,代码行数:40,代码来源:SeJsonWriter.cpp


注:本文中的json::Value::asString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。