JSON for Modern C++ 1.0.0-rc1

- Main Page
- Classes

allocator_type
array
array_t
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_pointer
const_reference
const_reverse_iterator
count
crbegin
crend
difference_type
dump
empty
end
end
erase
erase
erase
erase
find
find
front
front
get
get
get
get_allocator
get_ptr
get_ptr
insert
insert
insert
insert
insert
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_object
is_primitive
is_string
is_structured
max_size
number_float_t
number_integer_t
object
object_t
operator value_t
operator ValueType
operator!=
operator!=
operator!=
operator+=
operator+=
operator+=
operator<
operator<
operator<<
operator<<
operator<=
operator=
operator==
operator==
operator==
operator>
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
parse
parse
parse
parse_event_t
parser_callback_t
pointer
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
size
size_type
string_t
swap
swap
swap
swap
type
value
value
value_t
value_type
~basic_json
| template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator> template<class CompatibleArrayType , typename std::enable_if< not std::is_same< CompatibleArrayType, typename basic_json_t::iterator >::value and not std::is_same< CompatibleArrayType, typename basic_json_t::const_iterator >::value and not std::is_same< CompatibleArrayType, typename basic_json_t::reverse_iterator >::value and not std::is_same< CompatibleArrayType, typename basic_json_t::const_reverse_iterator >::value and not std::is_same< CompatibleArrayType, typename array_t::iterator >::value and not std::is_same< CompatibleArrayType, typename array_t::const_iterator >::value and std::is_constructible< basic_json, typename CompatibleArrayType::value_type >::value, int >::type = 0>
nlohmann::basic_json::basic_json | ( | const CompatibleArrayType & | value | ) |
| inline
  Create an array JSON value with a given content. This constructor allows any type that can be used to construct values of type array_t. Examples include the types `std::vector`, `std::list`, and `std::set`. Template Parameters
  CompatibleArrayType | an object type whose `value_type` is compatible to array_t
  Parameters
  [in] | value | a value for the array
  Complexity Linear in the size of the passed value. Exceptions
  std::bad_alloc | if allocation for array value fails
  Example The following code shows the constructor with several compatible array type parameters. 1 #include <json.hpp> 2 #include <deque> 3 #include <list> 4 #include <forward_list> 5 #include <set> 6 #include <unordered_set> 7 8 using namespace nlohmann; 9 10 int main() 11 { 12 // create an array from std::vector 13 std::vector<int> c_vector {1, 2, 3, 4}; 14 json j_vec(c_vector); 15 16 // create an array from std::deque 17 std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6}; 18 json j_deque(c_deque); 19 20 // create an array from std::list 21 std::list<bool> c_list {true, true, false, true}; 22 json j_list(c_list); 23 24 // create an array from std::forward_list 25 std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; 26 json j_flist(c_flist); 27 28 // create an array from std::array 29 std::array<unsigned long, 4> c_array {{1, 2, 3, 4}}; 30 json j_array(c_array); 31 32 // create an array from std::set 33 std::set<std::string> c_set {"one", "two", "three", "four", "one"}; 34 json j_set(c_set); // only one entry for "one" is used 35 36 // create an array from std::unordered_set 37 std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"}; 38 json j_uset(c_uset); // only one entry for "one" is used 39 40 // create an array from std::multiset 41 std::multiset<std::string> c_mset {"one", "two", "one", "four"}; 42 json j_mset(c_mset); // only one entry for "one" is used 43 44 // create an array from std::unordered_multiset 45 std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"}; 46 json j_umset(c_umset); // both entries for "one" are used 47 48 // serialize the JSON arrays 49 std::cout << j_vec << '\n'; 50 std::cout << j_deque << '\n'; 51 std::cout << j_list << '\n'; 52 std::cout << j_flist << '\n'; 53 std::cout << j_array << '\n'; 54 std::cout << j_set << '\n'; 55 std::cout << j_uset << '\n'; 56 std::cout << j_mset << '\n'; 57 std::cout << j_umset << '\n'; 58 } nlohmann::basic_json a class to store JSON values Definition: json.hpp:187 nlohmann namespace for Niels Lohmann Definition: json.hpp:78 Output (play with this example online):
      [1,2,3,4]
      [1.2,2.3,3.4,5.6]
      [true,true,false,true]
      [12345678909876,23456789098765,34567890987654,45678909876543]
      [1,2,3,4]
      ["four","one","three","two"]
      ["four","three","two","one"]
      ["four","one","one","two"]
      ["four","two","one","one"]
  The example code above can be translated with
      g++ -std=c++11 -Isrc doc/examples/basic_json__CompatibleArrayType.cpp -o basic_json__CompatibleArrayType
See also basic_json(const array_t&) – create an array value Since version 1.0 Definition at line 1029 of file json.hpp.