deploy: 4155e2938f
This commit is contained in:
1 parent
be4d0a6f4b
commit
90f0c9d411
714 files changed
+22067
-622
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <nlohmann/json_view.hpp>
|
||||
|
||||
using json_document = nlohmann::json_document;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
// a JSON value embedded in a larger, non-null-terminated buffer (e.g. a
|
||||
// slice received over the network)
|
||||
std::vector<char> buffer = {'[', '1', ',', '2', ']', 'j', 'u', 'n', 'k'};
|
||||
|
||||
// a pointer pair is BORROWED, exactly like a byte container lvalue: the
|
||||
// document points into the buffer. (From C++20 on, std::vector<char>
|
||||
// iterators are borrowed as well; before, they are copied.)
|
||||
const char* first = buffer.data();
|
||||
json_document doc = json_document::parse(first, first + 5);
|
||||
std::cout << doc.root().is_array() << ' ' << doc.root().size() << '\n';
|
||||
std::cout << doc.owns_source() << '\n'; // false: borrowed
|
||||
}
|
||||
Reference in new issue
Block a user