本文整理汇总了C++中json::ValueIterator类的典型用法代码示例。如果您正苦于以下问题:C++ ValueIterator类的具体用法?C++ ValueIterator怎么用?C++ ValueIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ValueIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCamera
void JsonParser::parseCamera(Json::Value &root){
LOG_DEBUG("Parsing Camera.");
bool foundCamera = false;
// Options
for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {
std::string key = itr.key().asString();
if (key == "renderCam") {
foundCamera = true;
// read all standard data
double r_fieldOfView = getDoubleAttr("fov", *itr);
Transform r_transform = getTransformAttr("transforms", *itr);
// TODO: check for any ones we've skipped and warn the user
// TODO: handle errors gracefully
// apply read data
(*renderEnv->globals)[FieldOfView] = r_fieldOfView;
cameraTransform = new Transform(r_transform);
LOG_DEBUG("Done parsing Camera.\n");
break;
}
}
if (!foundCamera) {
LOG_WARNING("No render camera found in file " << filename << ".");
}
}
示例2: DumpJsonTree
void JsonArchive::DumpJsonTree(Json::Value* root, int depth)
{
if (root == NULL)
{
root = &m_Root;
}
depth += 1;
printf( " {type=[%d], size=%d}", root->type(), root->size() );
if( root->size() > 0 )
{
printf("\n");
for( Json::ValueIterator itr = root->begin() ; itr != root->end() ; itr++ )
{
// Print depth.
for( int tab = 0 ; tab < depth; tab++)
{
printf("-");
}
printf(" subvalue(%s) -", itr.memberName());
DumpJsonTree( &(*itr), depth);
}
}
else
{
printf(" ");
PrintJsonValue(root);
printf( "\n" );
}
}
示例3: parseMaterials
void JsonParser::parseMaterials(Json::Value &root){
LOG_DEBUG("Parsing Materials.");
bool foundMaterials = false;
for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {
std::string key = itr.key().asString();
if (key == "materials") {
foundMaterials = true;
// loop through materials
Json::Value objRoot = *itr;
for( Json::ValueIterator objItr = objRoot.begin() ; objItr != objRoot.end() ; objItr++ ) {
std::string matName = objItr.key().asString();
LOG_DEBUG("Found material: " << matName);
// we first check if we're dealing with a light or mesh
std::string matType = getStringAttr("type", *objItr);
Material * mat = getMaterial(matType, matName, *objItr, renderEnv);
// add to shading engine
renderEnv->shadingEngine->registerMaterial(matName, mat);
}
LOG_DEBUG("Done parsing materials.\n");
break;
}
}
if (!foundMaterials) {
LOG_WARNING("No materials found in file " << filename << ".");
}
}
示例4: getLangs
Translator::Langs Translator::getLangs() const
{
_curlBuffer = "";
Translator::Langs langs;
std::string mylang = getMyLang();
if(mylang.empty())
mylang = "en"; // default
std::string url = "https://translate.yandex.net/api/v1.5/tr.json/getLangs?key=";
url += getApiKey();
url += "&ui=";
url += mylang;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());;
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
// error
}
Json::Reader reader;
Json::Value root;
reader.parse(_curlBuffer, root);
for(Json::ValueIterator it = root["langs"].begin(); it != root["langs"].end(); it++)
{
langs.push_back(std::make_pair(
it.key().asString(), // key
(*it).asString() // value
));
}
return langs;
}
示例5: JsonParseOrder
void Com::JsonParseOrder(Order_t* order){
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( buffer, root );
if ( !parsingSuccessful )
{
std::cout << "Failed to parse configuration\n"
<< reader.getFormattedErrorMessages();
return;
}
order->orderId = root["order_id"].asInt();
for( Json::ValueIterator itr = root["recipe"].begin() ; itr != root["recipe"].end() ; itr++ ) {
#ifdef DEBUG
std::cout << itr.key().asString() << " " << *itr;
#endif
order->ingredients.push_back(makeIngredientItem(itr.key().asString(), (*itr).asInt()));
}
#ifdef DEBUG
printf("parsing passed\n");
#endif
}
示例6: input
/**
* Read a map of {list_name : class_list} from json
*/
std::unordered_map<std::string, std::vector<std::string> > ConfigFiles::load_class_lists() {
std::unordered_map<std::string, std::vector<std::string> > lists;
std::string class_lists_filename;
this->m_json.get("class_lists", "", class_lists_filename);
if (class_lists_filename.empty()) {
return lists;
}
std::ifstream input(class_lists_filename);
Json::Reader reader;
Json::Value root;
bool parsing_succeeded = reader.parse(input, root);
always_assert_log(parsing_succeeded, "Failed to parse class list json from file: %s\n%s",
class_lists_filename.c_str(),
reader.getFormattedErrorMessages().c_str());
for (Json::ValueIterator it = root.begin(); it != root.end(); ++it) {
std::vector<std::string> class_list;
Json::Value current_list = *it;
for (Json::ValueIterator list_it = current_list.begin(); list_it != current_list.end(); ++list_it) {
lists[it.key().asString()].push_back((*list_it).asString());
}
}
lists["secondary_dex_head.list"] = get_coldstart_classes();
return lists;
}
示例7: fileContent
std::map<std::string, std::string>
jsonValueToAccount(Json::Value& value, const std::string& accountId) {
auto idPath_ = fileutils::get_data_dir() + DIR_SEPARATOR_STR + accountId;
fileutils::check_dir(idPath_.c_str(), 0700);
auto detailsMap = DRing::getAccountTemplate(value[DRing::Account::ConfProperties::TYPE].asString());
for( Json::ValueIterator itr = value.begin() ; itr != value.end() ; itr++ ) {
if (itr->asString().empty())
continue;
if (itr.key().asString().compare(DRing::Account::ConfProperties::TLS::CA_LIST_FILE) == 0) {
std::string fileContent(itr->asString());
fileutils::saveFile(idPath_ + DIR_SEPARATOR_STR "ca.key", {fileContent.begin(), fileContent.end()}, 0600);
} else if (itr.key().asString().compare(DRing::Account::ConfProperties::TLS::PRIVATE_KEY_FILE) == 0) {
std::string fileContent(itr->asString());
fileutils::saveFile(idPath_ + DIR_SEPARATOR_STR "dht.key", {fileContent.begin(), fileContent.end()}, 0600);
} else if (itr.key().asString().compare(DRing::Account::ConfProperties::TLS::CERTIFICATE_FILE) == 0) {
std::string fileContent(itr->asString());
fileutils::saveFile(idPath_ + DIR_SEPARATOR_STR "dht.crt", {fileContent.begin(), fileContent.end()}, 0600);
} else
detailsMap[itr.key().asString()] = itr->asString();
}
return detailsMap;
}
示例8:
Objects::Object::Object(Json::Value data) :
self_data( data ), self_x(0), self_y(0), self_w(0), self_h(0)
{
Json::Value dimensions = data["dimensions"];
if ( dimensions.isObject() )
{
// Coordinates are stored as doubles, but interpretted as either
// pixel coordinates or fractional. If ANY dimension is a double, then
// they all should be (why would you use a double coordinate otherwise?)
self_coordType = Objects::NON_NORM;
for ( Json::ValueIterator itr = dimensions.begin();
itr != dimensions.end();
itr ++ )
{
string key = itr.key().asString();
if (dimensions[ key ] . isDouble() )
{
self_coordType = Objects::NORM;
break;
}
}
self_x = dimensions["x"].asDouble();
self_y = dimensions["y"].asDouble();
}
}
示例9: deserializeEquippedItems
void ItemEquipper::deserializeEquippedItems(Json::Value& root) {
Item* item;
for (Json::ValueIterator it = root.begin(); it != root.end(); it++) {
item = new Item();
item->deserialize(*it);
_equippedItems[it.key().asInt()] = item;
}
}
示例10: readFromFile
bool CannyReader::readFromFile()
{
Timer aTimer;
std::ifstream cannyFile(srcFile);
cannyFile.precision(20);
if (cannyFile.is_open()) {
std::stringstream buffer;
buffer << cannyFile.rdbuf();
std::string contents(buffer.str());
cout << "Time to Read: " << aTimer.elapsed() << endl;
aTimer.restart();
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse( contents, root );
cout << "Time to parse: " << aTimer.elapsed() << endl;
aTimer.restart();
if (parsingSuccessful)
{
for( Json::ValueIterator outer = root.begin() ; outer != root.end() ; outer++ ) {
int camNum = outer.key().asInt();
Json::Value oneCam = root[camNum];
for( Json::ValueIterator itr = oneCam.begin() ; itr != oneCam.end() ; itr++ ) {
vector<Line_Segment *>* lineSegments = new vector<Line_Segment *>();
int key = atoi(itr.key().asCString());
Json::Value jsonSegments = oneCam[itr.key().asCString()];
for( Json::ValueIterator itr2 = jsonSegments.begin() ; itr2 != jsonSegments.end() ; itr2++ ) {
Json::Value jsonSeg = jsonSegments[itr2.key().asInt()];
Line_Segment* seg = (Line_Segment *) malloc(sizeof(Line_Segment));
seg->row1 = jsonSeg["r1"].asInt();
seg->col1 = jsonSeg["c1"].asInt();
seg->row2 = jsonSeg["r2"].asInt();
seg->col2 = jsonSeg["c2"].asInt();
lineSegments->push_back(seg);
}
precomputedCannySegments[camNum][key] = lineSegments;
}
}
cannyFile.close();
cout << "Time to reconstruct: " << aTimer.elapsed() << endl;
return true;
}
else {
return false;
}
}
return false;
}
示例11: Dropped
std::list<std::string> CJSONHandler::ParseAvailLanguagesTX(std::string strJSON, bool bIsXBMCCore, std::string strURL)
{
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
std::string lang;
std::list<std::string> listLangs;
bool parsingSuccessful = reader.parse(strJSON, root );
if ( !parsingSuccessful )
{
CLog::Log(logERROR, "CJSONHandler::ParseAvailLanguagesTX: no valid JSON data");
return listLangs;
}
const Json::Value langs = root;
std::string strLangsToFetch;
std::string strLangsToDrop;
std::string strLangsBlacklisted;
for(Json::ValueIterator itr = langs.begin() ; itr != langs.end() ; itr++)
{
lang = itr.key().asString();
if (lang == "unknown")
CLog::Log(logERROR, "JSONHandler: ParseLangs: no language code in json data. json string:\n %s", strJSON.c_str());
Json::Value valu = *itr;
std::string strCompletedPerc = valu.get("completed", "unknown").asString();
std::string strModTime = valu.get("last_update", "unknown").asString();
bool bLangBlacklisted = g_LCodeHandler.CheckIfLangCodeBlacklisted(lang);
// we only add language codes to the list which has a minimum ready percentage defined in the xml file
// we make an exception with all English derived languages, as they can have only a few srings changed
if (lang.find("en_") != std::string::npos || strtol(&strCompletedPerc[0], NULL, 10) > g_Settings.GetMinCompletion()-1 || !bIsXBMCCore)
{
if (!bLangBlacklisted)
{
strLangsToFetch += lang + ": " + strCompletedPerc + ", ";
listLangs.push_back(lang);
g_Fileversion.SetVersionForURL(strURL + "translation/" + lang + "/?file", strModTime);
}
else
{
strLangsBlacklisted += lang + ": " + strCompletedPerc + ", ";
}
}
else
strLangsToDrop += lang + ": " + strCompletedPerc + ", ";
};
CLog::Log(logINFO, "JSONHandler: ParseAvailLangs: Languages to be Fetcehed: %s", strLangsToFetch.c_str());
CLog::Log(logINFO, "JSONHandler: ParseAvailLangs: Languages to be Dropped (not enough completion): %s", strLangsToDrop.c_str());
CLog::Log(logINFO, "JSONHandler: ParseAvailLangs: Languages to be Dropped due they are blacklisted: %s",strLangsBlacklisted.c_str());
return listLangs;
};
示例12: getChatId
string HandlerChat::getChatId(string remitente,string destinatario){
/**Busca el chat id de la conversacion sino existe lo crea.**/
Json::Value chatsId=getChatsIdValueFromDestinatario(destinatario);
string id="";
for( Json::ValueIterator itr = chatsId.begin() ; itr != chatsId.end() ; itr++ ){
if((*itr).asString()==remitente){
id=itr.key().asString();
}
}
return id;
}
示例13: updateRegistry
bool updateRegistry(Json::Value &jsonRoot, Json::Value &outputRoot)
{
bool success = true;
for (Json::ValueIterator iter = jsonRoot.begin(); iter != jsonRoot.end(); iter++) {
Json::Value solutionsRoot = jsonRoot.get(iter.memberName(), Json::Value());
Json::Value solutionsOutput;
for(Json::ValueIterator itr = solutionsRoot["settings"].begin() ; itr != solutionsRoot["settings"].end() ; itr++ )
{
bool missingValue = false;
Json::Value currentOption;
const char * path = solutionsRoot["options"]["path"].asCString();
const char * valueName = itr.memberName();
long valueToSet = solutionsRoot["settings"][valueName].asUInt();
wstring updatedPath = toWideChar(path);
wstring updatedValueName = toWideChar(valueName);
long value = -1;
try
{
value = getDwordValue(hKeyFromString(solutionsRoot["options"]["hKey"].asCString()), updatedPath.c_str(), updatedValueName.c_str());
} catch (int exCode)
{
currentOption["statusCode"] = exCode;
currentOption["oldValue"] = Json::Value();
currentOption["newValue"] = Json::Value();
success = false;
missingValue = true;
}
bool valueSet = setDwordValue(hKeyFromString(solutionsRoot["options"]["hKey"].asCString()), updatedPath.c_str(), updatedValueName.c_str(), valueToSet);
if (missingValue)
{
currentOption["oldValue"] = Json::Value();
} else {
currentOption["oldValue"] = value;
}
try
{
currentOption["newValue"] = getDwordValue(hKeyFromString(solutionsRoot["options"]["hKey"].asCString()), updatedPath.c_str(), updatedValueName.c_str());
} catch (int exceptionCode) {
// TODO Handle gracefully.
}
if (!valueSet)
{
success = false;
currentOption["newValue"] = value;
}
solutionsOutput[valueName] = currentOption;
}
outputRoot[iter.memberName()]["results"] = solutionsOutput;
}
return success;
}
示例14: record
void ofApp::record(){
ofFile newfile(ofToDataPath("coordinates.json"), ofFile::WriteOnly);
string time = ofToString(ofGetElapsedTimef());
for(Json::ValueIterator i = untimedData.begin() ; i != untimedData.end(); i++) {
string id = i.key().asString();
data[id][time]["position"] = untimedData[id]["position"];
data[ofToString(id)][time]["rotation"] = untimedData[id]["rotation"];
cout << data;
}
if (data != ofxJSONElement::null)
newfile << data;
sound.play();
}
示例15: jsonToVariantList
qpid::types::Variant::Map agocontrol::jsonToVariantMap(Json::Value value) {
Variant::Map map;
try {
for (Json::ValueIterator it = value.begin(); it != value.end(); it++) {
// printf("%s\n",it.key().asString().c_str());
// printf("%s\n", (*it).asString().c_str());
if ((*it).size() > 0) {
// cout << "JSON Type: " << (*it).type() << endl;
// cout << "Key: " << it.key().asString() << endl;
if ((*it).type() == 6) {
map[it.key().asString()] = jsonToVariantList((*it));
} else if ((*it).type() == 7) {
map[it.key().asString()] = jsonToVariantMap((*it));
}
} else {
if ((*it).isString()) map[it.key().asString()] = (*it).asString();
if ((*it).isBool()) map[it.key().asString()] = (*it).asBool();
if ((*it).isInt()) map[it.key().asString()] = (*it).asInt();
if ((*it).isUInt()) map[it.key().asString()] = (*it).asUInt();
if ((*it).isDouble()) map[it.key().asString()] = (*it).asDouble();
}
}
} catch (const std::exception& error) {
cout << "ERROR! Exception during JSON->Variant::Map conversion!" << endl;
stringstream errorstring;
errorstring << error.what();
cout << "EXCEPTION: " << errorstring.str() << endl;
}
return map;
}