void JSONParseLog::JSONParseAndFill(picojson::value::object &obj, std::string indent) { picojson::value::object::const_iterator i = obj.begin(); for ( ; i != obj.end(); ++i ) { picojson::value v = i->second; if (i->second.is<picojson::object>()) { std::cout << indent << i->first << " : "<< std::endl; JSONParseAndFill(v.get<picojson::object>(), indent + " "); } else if (i->second.is<picojson::array>()) { std::cout << indent << i->first << " : ["<< std::endl; JSONParseAndFill(v.get<picojson::array>(), indent + " "); std::cout << " ]"<< std::endl; } else { std::cout << indent << i->first << " : " << i->second.to_str() << std::endl; //waiting weather.icon if (i->first == "icon") { std::shared_ptr<URL> spURL = APIConst::getURL(APIConst::Icon(i->second.to_str())); std::string logMessage = spURL->originalRequestString(); log(logMessage); Cache& cache = Cache::instance(); //log("Cache instance was created"); if (cache.check(spURL->originalRequestString()) != true){ //URL was not cached std::shared_ptr<HTTPRequest> request(new HTTPRequest(HTTPRequestType(HTTPRequestType::GET), spURL, HTTPProto(HTTPProto::HTTP1_0)) ); //log(spURL->originalRequestString()); request->setAction(std::make_shared<SaveFileAndCache>( i->second.to_str()+APIConst::instance().imgExtention, spURL) ); qmaster_.setHTTPRequest(request); } else { //URL was cached std::string fullPath = cache.getInfo(spURL->originalRequestString())->fullPath_; std::string logMessage = "URL " + spURL->originalRequestString() + " was already cached, "; logMessage += "Please look at " + fullPath + " file"; log(logMessage); } } } } }
void WeatherWidget::JSONParseAndFill(picojson::value::object &obj) { picojson::value::object::const_iterator i = obj.begin(); for ( ; i != obj.end(); ++i ) { picojson::value v = i->second; if (i->second.is<picojson::object>()) { JSONParseAndFill(v.get<picojson::object>()); } else if (i->second.is<picojson::array>()) { JSONParseAndFill(v.get<picojson::array>()); } else { setText(QString().fromStdString(i->first), QString().fromStdString(i->second.to_str()) ); } } }