Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
CJSONElement::~CJSONElement()
{
  if (m_type == TYPESTRING)
  {
    delete (string*)m_data.m_ptr;
  }
  else if (m_type == TYPEMAP)
  {
    JSONMap* map = (JSONMap*)m_data.m_ptr;
    for (JSONMap::iterator it = map->begin(); it != map->end(); it++)
      delete it->second;

    delete (JSONMap*)m_data.m_ptr;
  }
  else if (m_type == TYPEARRAY)
  {
    JSONArray* array = (JSONArray*)m_data.m_ptr;
    for (JSONArray::iterator it = array->begin(); it != array->end(); it++)
      delete *it;

    delete (JSONArray*)m_data.m_ptr;
  }

  delete m_error;
}
Пример #4
0
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;
}