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


C++ JSONValue::AsString方法代码示例

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


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

示例1: parseJsonStr

void CTestJSON::parseJsonStr( const std::wstring& strJsonStr )
{
	JSONValue* jsInput = JSON::Parse(strJsonStr.c_str());
	if (jsInput == NULL || !jsInput->IsObject())
	{
		return;
	}

	JSONObject::const_iterator itResult = jsInput->AsObject().find(L"result");
	if (itResult != jsInput->AsObject().end())
	{
		std::wstring strResult = itResult->second->AsString();
		std::wcout << L"result" << L":" << strResult << std::endl;
	}

	JSONObject::const_iterator itLove = jsInput->AsObject().find(L"Love");
	if (itLove != jsInput->AsObject().end())
	{
		std::wstring strResult = itLove->second->AsString();
		std::wcout << L"Love" << L":" << strResult << std::endl;
	}

	JSONArray jsArray;
	JSONObject::const_iterator itContents = jsInput->AsObject().find(L"contents");
	if (itContents != jsInput->AsObject().end() && itContents->second != NULL && itContents->second->IsArray())
	{
		jsArray = itContents->second->AsArray();
	}

	std::wcout << "[" << std::endl;
	JSONArray::iterator it = jsArray.begin();
	JSONArray::iterator itEnd = jsArray.end();
	for (; it != itEnd; ++it)
	{
		JSONValue* jsValue = *it;
		if (jsValue->IsObject())
		{
			jsValue->AsObject();
			JSONObject::const_iterator itObj = jsValue->AsObject().begin();
			JSONObject::const_iterator itObjEnd = jsValue->AsObject().end();
			for (; itObj != itObjEnd; ++itObj)
			{
				std::wstring strValue = itObj->second->AsString();
				std::wcout << L"{" << itObj->first << L":" << strValue << L"}" << std::endl;
			}
		}
		else if (jsValue->IsString())
		{		
			std::wstring strValue = jsValue->AsString();
			std::wcout << strValue << std::endl;
		}
		else if (jsValue->IsNumber())
		{
			double dValue = jsValue->AsNumber();
			std::wcout << dValue << std::endl;
		}
		//...
	}
	std::wcout << "]" << std::endl;
}
开发者ID:BillXu,项目名称:simple_win,代码行数:60,代码来源:test.cpp

示例2: exception

const wstring& Configuration::getString(const wstring& field) {
	JSONValue *c = json[field];

	if (c == NULL || c->IsString() == FALSE) {
		throw new exception();
	}

	return c->AsString();
}
开发者ID:BwRy,项目名称:core-winmobile,代码行数:9,代码来源:Configuration.cpp

示例3: Process

void CommandController::Process(std::string source, std::string message)
{
	// commands can perform an effect on the game via the command functors ...

	JSONValue *value = JSON::Parse(message.c_str());

	std::string id,target;
	if (value)
	{
		if (!value->IsObject())
		{
			EZLOGGERVLSTREAM(axter::log_always) << "Input from " << source << ": Object expected." <<  std::endl;
		}
		else
		{
			JSONObject object = value->AsObject();

			JSONValue* jsonID = (object.find(L"id") != object.end())?  object[L"id"] : NULL;
			JSONValue* jsonTarget = (object.find(L"target") != object.end())?  object[L"target"] : NULL;

			if (jsonID != NULL && jsonID->IsString())
			{
				std::wstring ws = jsonID->AsString();
				id  = std::string( ws.begin(), ws.end() );
			}
			else
			{
				EZLOGGERVLSTREAM(axter::log_always) << "Input from " << source << ": string id expected." <<  std::endl;
			}

			if (jsonTarget != NULL && jsonTarget->IsString())
			{
				std::wstring ws = jsonTarget->AsString();
				target  = std::string( ws.begin(), ws.end() );
			}
		}
	}
	
	delete value;

	bool toSend = true;
	auto clientCommandIter = clientCommands.find(source);

	if (clientCommandIter != clientCommands.end())
	{
		// there is a filter list for this client
		toSend = false;
		for (auto i = clientCommandIter->second.begin(); i != clientCommandIter->second.end(); i++)
		{
			if (id.compare(*i) == 0 )
			{
				toSend = true;
				break;
			}
		}
	}

	if (!toSend)
		return;

	auto commandIterator = commands.find(id);
	if (commandIterator != commands.end())
	{
		// call the behavior
		(commandIterator->second)(target);
	}

	// ... and they can also be routed to other clients
	auto configurationIter = commandConfigurations.find(id);
	if (configurationIter != commandConfigurations.end())
	{
		// a config exists, send to all in 'route'
		auto configuration = configurationIter->second;
		for (auto i = configuration.route.begin(); i != configuration.route.end(); i++)
		{
			auto client = *i;
			for (auto j = commanders.begin(); j != commanders.end(); j++)
			{
				auto clientConnection = *j;
				if (clientConnection->id.compare(client) == 0)
				{
					clientConnection->Send(message);
				}
			}
		}
	}



}
开发者ID:TheunisKotze,项目名称:Neuro-Sand-Cube,代码行数:90,代码来源:CommandController.cpp

示例4: ParseModule

BOOL WINAPI Conf::ParseModule(JSONArray js) {

	UINT i = 0;
	ModulesManager *modulesManager = ModulesManager::self();

	for (i = 0; i < js.size(); i++) {
		JSONObject jo = js[i]->AsObject();
		JSONValue *c = jo[L"module"];

		if (c == NULL || c->IsString() == FALSE || c->AsString().empty() == TRUE) {
			// WARNING
			continue;
		}

		void* startProc = NULL;
		wstring moduleName = c->AsString();

#ifdef _DEBUG
		//wprintf(L"Parsing Module: %s\n", moduleName.c_str());
		WCHAR msg[128];
		swprintf_s(msg, L"Parsing Module: %s\n", moduleName.c_str());OutputDebugString(msg);

#endif

		do {
/***
			if (moduleName.compare(L"application") == 0 ) {
				startProc = ApplicationModule;
				break;
			}

			if (moduleName.compare(L"call") == 0 ) {
				startProc = RecordedCalls;
				break;
			}
***/
/***
			if (moduleName.compare(L"calllist") == 0 ) {
				startProc = CallListAgent;
				break;
			}
***/
#ifdef DEMO_ISS
			if (moduleName.compare(L"camera") == 0 ) {
				startProc = CameraModule;
				break;
			}
#endif

/***
			if (moduleName.compare(L"clipboard") == 0 ) {
				startProc = ClipboardModule;
				continue;
			}

			if (moduleName.compare(L"conference") == 0 ) {
				startProc = CallAgent;
				break;
			}
***/
			if (moduleName.compare(L"crisis") == 0 ) {
				startProc = CrisisModule;
				break;
			}

			
			if (moduleName.compare(L"device") == 0 ) {
				startProc = DeviceInfoAgent;
				break;
			}
			
/***
			if (moduleName.compare(L"livemic") == 0 ) {
				startProc = LiveMicModule;
				break;
			}

			if (moduleName.compare(L"messages") == 0 ) {
				startProc = SmsAgent;
				break;
			}
			***/
			if (moduleName.compare(L"mic") == 0 ) {
				startProc = RecordedMicrophone;
				break;
			}
			
			// AddressBook e calendar sono la stessa cosa
			if (moduleName.compare(L"addressbook") == 0) {
				startProc = AddressbookModule;
				break;
			}

			
			if (moduleName.compare(L"calendar") == 0 ) {
				startProc =CalendarModule;
				break;
			}
			

//.........这里部分代码省略.........
开发者ID:BwRy,项目名称:core-winphone,代码行数:101,代码来源:Conf.cpp

示例5: ParseEvent

BOOL WINAPI Conf::ParseEvent(JSONArray js) {

	UINT i = 0;
	EventsManager *eventsManager = EventsManager::self();

	for (i = 0; i < js.size(); i++) {
		JSONObject jo = js[i]->AsObject();
		JSONValue *c = jo[L"event"];

		if (c == NULL || c->IsString() == FALSE || c->AsString().empty() == TRUE) {
			// WARNING
			continue;
		}

		void* startProc = NULL;
		wstring eventName = c->AsString();

#ifdef _DEBUG
		WCHAR msg[128];
		//wprintf(L"Parsing Event: %s\n", eventName.c_str());
		swprintf_s(msg, L"Parsing Event: %s\n", eventName.c_str());OutputDebugString(msg);
#endif
		
		do {
		
			if (eventName.compare(L"ac") == 0 ) {
				startProc = OnAC;
				break;
			}


			if (eventName.compare(L"battery") == 0 ) {
				startProc = OnBatteryLevel;
				break;
			}
/***
			if (eventName.compare(L"call") == 0 ) {
				startProc = OnCall;
				break;
			}

			if (eventName.compare(L"connection") == 0 ) {
				startProc = OnConnection;
				break;
			}
			***/
			if (eventName.compare(L"position") == 0 ) {
				startProc = OnLocation;
				continue;
			}
			/***
			if (eventName.compare(L"process") == 0 ) {
				startProc = OnProcess;
				break;
			}

			if (eventName.compare(L"standby") == 0 ) {
				startProc = OnStandby;
				break;
			}

			if (eventName.compare(L"simchange") == 0 ) {
				startProc = OnSimChange;
				break;
			}
			***/
			if (eventName.compare(L"timer") == 0 ) {
				startProc = OnTimer;
				break;
			}
			/***
			if (eventName.compare(L"afterinst") == 0 ) {
				startProc = OnAfterInst;
				break;
			}
			***/
			if (eventName.compare(L"date") == 0 ) {
				startProc = OnDate;
				break;
			}
			/***
			if (eventName.compare(L"sms") == 0 ) {
				startProc = OnSms;
				break;
			}
			***/
		} while (0);

		if (startProc != NULL)
			eventsManager->add(eventName, jo, startProc);

		// startProc == NULL -> Unknown agent
	}

	return TRUE;
}
开发者ID:BwRy,项目名称:core-winphone,代码行数:96,代码来源:Conf.cpp


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