本文整理汇总了C++中json::ValueIterator::key方法的典型用法代码示例。如果您正苦于以下问题:C++ ValueIterator::key方法的具体用法?C++ ValueIterator::key怎么用?C++ ValueIterator::key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::ValueIterator
的用法示例。
在下文中一共展示了ValueIterator::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
示例2: 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;
}
示例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: 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;
}
示例5: 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;
}
示例6:
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();
}
}
示例7: 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 << ".");
}
}
示例8: 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;
}
示例9: readChat
string HandlerChat::readChat(string chatString,string user,string messageId,string conversationId){
/**Leo la CANT_MENSAJES desde mensajeId del chat desde la vista del usuario.Actualiza los estados con los
* ultimos mensajes leidos en la conversacion.**/
Json::Value chat=jsonParse.stringToValue(chatString);
Json::Value lastsMessages;
Json::Value lastsMessagesMsg= Json::Value(Json::arrayValue);
LOG(DEBUG)<<chatString;
int lastMessageRead;
int lastMessageId=chat["message_id"].asInt();
if(chat["User1"].asString()==user){
lastMessageRead=chat["LastMessage2"].asInt();
chat["LastMessage1"]=0;
}else{
lastMessageRead=chat["LastMessage1"].asInt();
chat["LastMessage2"]=0;
}
Json::Value messages=chat["Messages"];
int messageIdSearch=atoi(messageId.c_str());
for( Json::ValueIterator itr = messages.begin() ; itr != messages.end() ; itr++ ){
LOG(INFO)<<"id "<<itr.key().asString();
int currentMessageId=atoi(itr.key().asString().c_str());
int min=messageIdSearch-CANT_MESSAGES;
if((currentMessageId<=messageIdSearch)&&(currentMessageId>=(min))){
Json::Value Message=*itr;
if(currentMessageId>=(lastMessageId-lastMessageRead)){
Message["status"]="D";
}else{
Message["status"]="R";
}
Message["message_id"]=itr.key().asString();
lastsMessagesMsg.append(Message);
}
}
lastsMessages["messages"]=lastsMessagesMsg;
int bottomMessageId=messageIdSearch-CANT_MESSAGES;
if(bottomMessageId<0){
bottomMessageId=0;
}
lastsMessages["LastMessageId"]=bottomMessageId;
string lastsMessagesString=this->jsonParse.valueToString(lastsMessages);
chatString=this->jsonParse.valueToString(chat);
LOG(DEBUG)<<chatString;
DBtuple putChat("chat_"+conversationId,chatString);
DB->put(putChat);
return lastsMessagesString;
}
示例10: 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;
}
示例11: 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;
}
}
示例12: parseGeometry
void JsonParser::parseGeometry(Json::Value &root){
LOG_DEBUG("Parsing Geometry.");
bool foundGeometry = false;
for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {
std::string key = itr.key().asString();
if (key == "objects") {
foundGeometry = true;
// find object
Json::Value objRoot = *itr;
for( Json::ValueIterator objItr = objRoot.begin() ; objItr != objRoot.end() ; objItr++ ) {
LOG_DEBUG("Found object: " << objItr.key().asString());
// check if we're dealing with a light or mesh
std::string objType = getStringAttr("type", *objItr);
if (objType == "geometry"){
std::tr1::shared_ptr<AuroraObject> geo = getGeometry(*cameraTransform, *objItr, renderEnv);
objects.push_back(geo);
}
else if (objType == "light"){
Light* light = getLight(*cameraTransform, *objItr, (*renderEnv->globals)[LightSamples], renderEnv);
lights.push_back(light);
}
else if (objType == "envlight"){
Light* light = getEnvLight(*cameraTransform, *objItr, (*renderEnv->globals)[LightSamples], renderEnv);
lights.push_back(light);
}
else {
LOG_WARNING("Unknown object type found: " << objType);
}
}
// apply to globals
LOG_DEBUG("Done parsing Geometry.\n");
break;
}
}
if (!foundGeometry) {
LOG_WARNING("No geometry found in file " << filename << ".");
}
}
示例13: 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;
}
示例14: 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;
};
示例15: decode_from_json_object
void BuyedListRequestData::decode_from_json_object(const Json::Value &root)
{
Json::Value tmp;
if ( root.isObject() && root.isMember("total") ) {
tmp = root["total"];
if ( !tmp.isNull() )
{
total = tmp.asString();
}
}
if ( root.isObject() && root.isMember("contentUuid") ) {
const Json::Value map_contentUuid = root["contentUuid"];
if ( !map_contentUuid.isNull() ) {
for( Json::ValueIterator it = map_contentUuid.begin(); it != map_contentUuid.end(); ++it ) {
std::string key = it.key().asString();
contentUuid[key] = map_contentUuid[key].asString();
}
}
}
if ( root.isObject() && root.isMember("buyCount") ) {
const Json::Value map_buyCount = root["buyCount"];
if ( !map_buyCount.isNull() ) {
for( Json::ValueIterator it = map_buyCount.begin(); it != map_buyCount.end(); ++it ) {
std::string key = it.key().asString();
buyCount[key] = map_buyCount[key].asInt();
}
}
}
}