|
◆ json_pointer()
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 = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE= void > class JSONSerializer = adl_serializer>
Create a JSON pointer according to the syntax described in Section 3 of RFC6901.
- Parameters
-
[in] | s | string representing the JSON pointer; if omitted, the empty string is assumed which references the whole JSON value |
- Exceptions
-
std::domain_error | if reference token is nonempty and does not begin with a slash (/ ); example: "JSON pointer must be empty or
begin with /" |
std::domain_error | if a tilde (~ ) is not followed by 0 (representing ~ ) or 1 (representing / ); example: "escape error:
~ must be followed with 0 or 1" |
- Example\n The example shows the construction several valid JSON
- pointers as well as the exceptional behavior.
22 catch (std::domain_error& e)
24 std::cout << "domain_error: " << e.what() << '\n';
32 catch (std::domain_error& e)
34 std::cout << "domain_error: " << e.what() << '\n';
40 json::json_pointer p11( "/foo/~3");
42 catch (std::domain_error& e)
44 std::cout << "domain_error: " << e.what() << '\n';
static basic_json array(std::initializer_list< basic_json > init=std::initializer_list< basic_json >()) explicitly create an array from an initializer list
a class to store JSON values
basic_json<> json default JSON class
Output (play with this example online):
domain_error: JSON pointer must be empty or begin with '/'
domain_error: escape error: '~' must be followed with '0' or '1'
domain_error: escape error: '~' must be followed with '0' or '1'
The example code above can be translated with g++ -std=c++11 -Isrc doc/examples/json_pointer.cpp -o json_pointer
- Since
- version 2.0.0
Definition at line 11127 of file json.hpp.
|