本文整理汇总了C++中json::value::as_array方法的典型用法代码示例。如果您正苦于以下问题:C++ value::as_array方法的具体用法?C++ value::as_array怎么用?C++ value::as_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::value
的用法示例。
在下文中一共展示了value::as_array方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_search_results
void print_search_results(json::value const & value)
{
if (!value.is_null())
{
//auto response = value.at(L"data");
//auto results = response[L"movies"];
// iteration is supported not directly on json::value but on
// json::object and json::array. Use json::value::as_object() and json::value::as_array().
std::wcout << value.as_array().at(0) << std::endl;
for (auto const & o : value.as_array())
{
auto id = o.at(L"id");
auto name = o.at(L"name");
auto username = o.at(L"username");
auto email = o.at(L"email");
auto address = o.at(L"address");
auto street = address.at(L"street");
std::wcout << id << std::endl << name << std::endl << username << std::endl << email << std::endl << street << std::endl << std::endl;
}
}
}
示例2: flattenJsonInnerLoop
void GoogleSearchClient::flattenJsonInnerLoop(json::value const & val, FlatJsonObject & json_map) {
// input : Body of the google search response as json::value
// This recursive function parse the Json raw value to a C++ multimap
if (!val.is_null() && val.is_object()) {
for (auto const &iter : val.as_object()) {
//iter on each element for Json object type. Return a vect<string_t,json::value>
const auto &mapKey = iter.first;
const auto &content = iter.second;
json_map.insert(std::pair<utility::string_t, utility::string_t>(mapKey, content.serialize()));
flattenJsonInnerLoop(content, json_map);
}
} else if (val.is_array()) {
for (auto const &content : val.as_array()) {
//iter on each element for Json array type. Return a json::value
flattenJsonInnerLoop(content, json_map);
}
}
}