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


C++ value::is_object方法代码示例

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


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

示例1: __print_container

static void __print_container (string & result
        , json::value const & value
        , print_spec const & pspec
        , int indent)
{
    if (value.size() == 0) { 
        __print_open_brace(result, value, pspec);
        __print_close_brace(result, value, pspec);
        return;
    }
    
    json::value::const_iterator it_begin = value.cbegin();
    json::value::const_iterator it_end   = value.cend();
    json::value::const_iterator it       = it_begin;
    json::value::const_iterator it_next  = it_begin;
        
    ++it_next;
    
    indent += pspec.base_indent;
    
    __print_open_brace(result, value, pspec);
    result.append(pspec.new_line); // container content always begin after new line
    
    for (; it != it_end; ++it, ++it_next) {
        if (it == it_begin) {
            __print_indent(result, pspec, indent);
            
            if (pspec.comma_position == json::comma_next_line) {
                __print_indent(result, pspec, pspec.first_item_indent);
            }
        }
        
        if (value.is_object()) {
            __print_value(result, it.key(), *it, pspec, indent);
        } else {
            __print_value(result, *it, pspec, indent);
        }
        
        if (it_next != it_end) {
            __print_comma(result, pspec, indent);
        }
    }
    
    indent -= pspec.base_indent;    
    
    result.append(pspec.new_line);
    __print_indent(result, pspec, indent);
    __print_close_brace(result, value, pspec);
}
开发者ID:semenovf,项目名称:pfs-json,代码行数:49,代码来源:pretty_print.cpp

示例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);
    }
  }
}
开发者ID:pdib,项目名称:ppt-forgery,代码行数:18,代码来源:GoogleSearchClient.cpp

示例3: _build_request

http::http_request http_client_impl::_build_request(http::method method, http::uri_builder request_uri, const ::utility::string_t& accept, json::value object) const
{
    http::http_request msg(method);

    if (!accept.empty())
        msg.headers().add(U("Accept"), accept);

    msg.set_request_uri(request_uri.to_uri());

    if (method == http::methods::POST || method == http::methods::PUT || method == http::methods::PATCH)
    {
        if(object.is_null() || !object.is_object())
            throw std::invalid_argument("POST, PUT, and PATCH requests require a payload");

        msg.set_body(object);
    }

    return msg;
}
开发者ID:zjufish,项目名称:odatacpp,代码行数:19,代码来源:http_implement.cpp

示例4: packed_print

    REQUIRE( json::value{'A'}.get_contents() == "65" );

    // Constructing with a json::array should produce array values
    json::value array_value = json::array{2,3.14f,"foo",false,nullptr};
    REQUIRE( array_value.is_array() );
    REQUIRE( array_value.get_array().size() == 5 );
    REQUIRE( array_value[0] == 2 );
    REQUIRE( array_value[1] == 3.14f );
    REQUIRE( array_value[2] == "foo" );
    REQUIRE( array_value[3] == false );
    REQUIRE( array_value[4] == nullptr );
    REQUIRE( array_value.get_kind() == json::kind::array );

    // Constructing with a json::object should produce object values
    json::value object_value = json::object{{"a",2},{"b",3.14f},{"c","foo"},{"d",false},{"e",nullptr}};
    REQUIRE( object_value.is_object() );
    REQUIRE( object_value.get_object().size() == 5 );
    REQUIRE( object_value["a"] == 2 );
    REQUIRE( object_value["b"] == 3.14f );
    REQUIRE( object_value["c"] == "foo" );
    REQUIRE( object_value["d"] == false );
    REQUIRE( object_value["e"] == nullptr );
    REQUIRE( object_value.get_kind() == json::kind::object );
}

std::string packed_print(const json::value & v) { std::ostringstream ss; ss << v; return ss.str(); }
std::string pretty_print(const json::value & v) { std::ostringstream ss; ss << tabbed(v, 4); return ss.str(); }

TEST_CASE( "printing" )
{
    REQUIRE( packed_print(5) == "5" );
开发者ID:sgorsten,项目名称:json,代码行数:31,代码来源:json-test.cpp


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