Skip to content

Commit 7e368ef

Browse files
committed
Update README
1 parent cec2ec3 commit 7e368ef

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@ in your source code to use JSON Pointer.
4040
#include <iostream>
4141
#include <array>
4242

43+
// Create a JSON pointer object
44+
json_pointer jp (L"/foo/1");
45+
4346
// Create a JSON object
44-
format::json j = L"{ \"foo\": [\"bar\", \"baz\"],\
45-
\"\": 0,\
46-
\"a/b\": 1,\
47-
\"c%d\": 2,\
48-
\"e^f\": 3,\
49-
\"g|h\": 4,\
50-
\"i\\j\": 5,\
51-
\" \": 7,\
52-
\"m~n\": 8 }";
47+
json j = L"{ \"foo\": [\"bar\", \"baz\"],\
48+
\"\": 0,\
49+
\"a/b\": 1,\
50+
\"c%d\": 2,\
51+
\"e^f\": 3,\
52+
\"g|h\": 4,\
53+
\"i\\j\": 5,\
54+
\" \": 7,\
55+
\"m~n\": 8 }";
56+
57+
// Get the value the pointer refers to
58+
value & v = jp.value (j);
59+
60+
std::wcout << v.as<const wchar_t *>() << std::endl;
61+
// ouput: baz
5362

5463
// Create an array of JSON pointers
5564
std::array<format::json_pointer, 13> jp_list = {
@@ -73,7 +82,7 @@ for (auto& jp : jp_list)
7382
{
7483
try {
7584
// Look for the value in the JSON object
76-
format::json::value & v = jp.get (j);
85+
format::json::value & v = jp.value (j);
7786

7887
// If value is not found, object type is undefined
7988
if (v.type () == format::json::value::undefined_t)

0 commit comments

Comments
 (0)