当前位置: 首页>>代码示例>>C++>>正文


C++ const_iterator::name方法代码示例

本文整理汇总了C++中json::value::const_iterator::name方法的典型用法代码示例。如果您正苦于以下问题:C++ const_iterator::name方法的具体用法?C++ const_iterator::name怎么用?C++ const_iterator::name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在json::value::const_iterator的用法示例。


在下文中一共展示了const_iterator::name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: push_json_value_helper

// Recursive function to convert JSON --> Lua table
static bool push_json_value_helper(lua_State *L, const Json::Value &value,
		int nullindex)
{
	switch(value.type()) {
		case Json::nullValue:
		default:
			lua_pushvalue(L, nullindex);
			break;
		case Json::intValue:
			lua_pushinteger(L, value.asInt());
			break;
		case Json::uintValue:
			lua_pushinteger(L, value.asUInt());
			break;
		case Json::realValue:
			lua_pushnumber(L, value.asDouble());
			break;
		case Json::stringValue:
			{
				const char *str = value.asCString();
				lua_pushstring(L, str ? str : "");
			}
			break;
		case Json::booleanValue:
			lua_pushboolean(L, value.asInt());
			break;
		case Json::arrayValue:
			lua_newtable(L);
			for (Json::Value::const_iterator it = value.begin();
					it != value.end(); ++it) {
				push_json_value_helper(L, *it, nullindex);
				lua_rawseti(L, -2, it.index() + 1);
			}
			break;
		case Json::objectValue:
			lua_newtable(L);
			for (Json::Value::const_iterator it = value.begin();
					it != value.end(); ++it) {
#ifndef JSONCPP_STRING
				const char *str = it.memberName();
				lua_pushstring(L, str ? str : "");
#else
				std::string str = it.name();
				lua_pushstring(L, str.c_str());
#endif
				push_json_value_helper(L, *it, nullindex);
				lua_rawset(L, -3);
			}
			break;
	}
	return true;
}
开发者ID:kaeza,项目名称:minetest,代码行数:53,代码来源:c_content.cpp

示例2: ParseFromJsonInternal

bool Tree::ParseFromJsonInternal(const Json::Value &json)
{
    size_t index = 0;
    for (Json::Value::const_iterator p = json.begin(); p != json.end(); ++p) {
        const Json::Value &j = *p;
        std::string key = p.name();
        if (key.empty()) {
            std::ostringstream s;
            s << '[' << index++ << ']';
            key = s.str();
        }

        std::string full_path = GetFullPath(key);
        if (j.isArray() || j.isObject()) { // Go recursively.
            Tree *child = new Tree(full_path, key, std::string());
            _children.insert(std::make_pair(key, child));

            if (!child->ParseFromJsonInternal(j)) {
                return false;
            }

            continue;
        }

        std::ostringstream s;
#ifdef JSON_HAS_INT64
        if (j.isInt64() ) { s << j.asInt64();   } else
        if (j.isUInt64()) { s << j.asUInt64();  } else
#endif
        if (j.isInt()   ) { s << j.asInt();     } else
        if (j.isUInt()  ) { s << j.asUInt();    } else
        if (j.isDouble()) { s << j.asDouble();  } else
                          { s << j.asString();  }

        const std::string &value = s.str();
        Tree *child = new Tree(full_path, key, value);
        _children.insert(std::make_pair(key, child));
    }

    return true;
}
开发者ID:goreliu,项目名称:flinter,代码行数:41,代码来源:tree_json.cpp


注:本文中的json::value::const_iterator::name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。