|
|
◆ 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>
| nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_pointer::json_pointer |
( |
const std::string & |
s = "" | ) |
|
|
inlineexplicit |
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
- The example shows the construction several valid JSON pointers as well as the exceptional behavior.
9 json::json_pointer p2( ""); 10 json::json_pointer p3( "/"); 11 json::json_pointer p4( "//"); 12 json::json_pointer p5( "/foo/bar"); 13 json::json_pointer p6( "/foo/bar/-"); 14 json::json_pointer p7( "/foo/~0"); 15 json::json_pointer p8( "/foo/~1"); 20 json::json_pointer p9( "foo"); 22 catch (std::domain_error& e) 24 std::cout << "domain_error: " << e.what() << '\n'; 30 json::json_pointer p10( "/foo/~"); 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'; 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 withg++ -std=c++11 -Isrc doc/examples/json_pointer.cpp -o json_pointer
- Since
- version 2.0.0
Definition at line 11368 of file json.hpp.
|