void LocalHighscores::parse() { ARK2D::getLog()->v("Parsing LocalHighscores"); string s; #if defined(ARK2D_ANDROID) if (m_threaded && m_data != NULL) { s = string((char*) m_data); } else if (StringUtil::file_exists(m_filename.c_str())) { s = StringUtil::file_get_contents(m_filename.c_str()); } else { s = string((char*) m_data); } #else if (m_data != NULL) { s = string((char*) m_data); } else { s = StringUtil::file_get_contents(m_filename.c_str()); } #endif ARK2D::getLog()->v(StringUtil::append("JSON String is: ", s)); if (s.length() == 0) { ARK2D::getLog()->e("JSON String was empty. Huh?"); return; } if (s == "[]") { ARK2D::getLog()->v("Local highscores were blank. That's fine. "); } else { JSONNode* arr = libJSON::Parse(s); if (arr == NULL) { ARK2D::getLog()->e("Could not parse json"); return; } for(unsigned int i = 0; i < arr->NodeSize(); i++) { JSONNode* item = arr->NodeAt(i); LocalHighscoreItem* it = new LocalHighscoreItem(); it->name = item->GetNode("name")->NodeAsString(); it->score = item->GetNode("score")->NodeAsInt(); //StringUtil::str_replace("\"", "\\\"", it->name); m_items.push_back(it); } ARK2D::getLog()->i("loaded local highscores"); // fix memory leaks ARK2D::getLog()->i("Freeing up memory."); libJSON::Delete(arr); } this->sort(); }
PathGroup* PathIO::createFromJSON(string json) { #ifdef EXCEPTIONS_AVAILABLE try { #endif JSONNode* root = libJSON::Parse(json); PathGroup* pathGroup = new PathGroup(); pathGroup->setName(root->GetNode("name")->NodeAsString()); pathGroup->setDescription(root->GetNode("description")->NodeAsString()); if (root->GetNode("relative") == NULL) { pathGroup->setRelative(false); } else { pathGroup->setRelative(root->GetNode("relative")->NodeAsBool()); } JSONNode* paths = root->GetNode("paths"); for(unsigned int i = 0; i < paths->NodeSize(); i++) { JSONNode* path = paths->Children[i]; Path* pathObj = new Path(); pathObj->setDuration(path->GetNode("duration")->NodeAsFloat()); pathObj->setEasing(Easing::getByString(path->GetNode("easing")->NodeAsString())); JSONNode* points = path->GetNode("points"); for(unsigned int j = 0; j < points->NodeSize(); j++) { JSONNode* point = points->Children[j]; pathObj->addPoint(point->GetNode("x")->NodeAsInt(), point->GetNode("y")->NodeAsInt()); } pathGroup->addPath(pathObj); } return pathGroup; #ifdef EXCEPTIONS_AVAILABLE } catch(...) { ErrorDialog::createAndShow("exception in PathIO::createFromJson"); return NULL; } #endif return NULL; }
void CBrowserDlg::NavigateComplete2Explorer1(LPDISPATCH pDisp, VARIANT* URL) { // “ут мы ловим редиректы. KillTimer(100); CString u=ie.get_LocationURL(); if(logout){ if(u.Find(L"http://vkontakte.ru/login.php")==0){ // «начит в IE уже вышли, закрываем окно CDialog::OnOK(); } if(logoutClicked){ CDialog::OnOK(); } } if(u.Find(L"http://vkontakte.ru/api/login_success.html")==0){ wchar_t* _url=URL->bstrVal; wcstok(_url, L"="); wchar_t* session_data=wcstok(NULL, L"="); std::wstring sd(CUtils::urlDecode(session_data)); JSONNode* json = libJSON::Parse(sd); wchar_t* wsid=(wchar_t*)json->GetNode(L"sid")->NodeAsString().c_str(); wchar_t* wsecret=(wchar_t*)json->GetNode(L"secret")->NodeAsString().c_str(); wchar_t* uid_s=(wchar_t*)json->GetNode(L"mid")->NodeAsString().c_str(); char* uid_c=CUtils::wtoc(uid_s, wcslen(uid_s)); uid=atoi(uid_c); sid=CUtils::wtoc(wsid, wcslen(wsid)+1); secret=CUtils::wtoc(wsecret, wcslen(wsecret)+1); delete [] wsid, wsecret, uid_s, uid_c; CDialog::OnOK(); } if(u.Find(L"http://vkontakte.ru/api/login_failure.html")==0){ MessageBox(L"јвторизаци¤ не удалась.", NULL, MB_OK | MB_ICONEXCLAMATION); CDialog::OnCancel(); } }