mirror of
https://github.com/nlohmann/json.git
synced 2026-10-13 09:47:12 +00:00
deploy: 40a62947d3
This commit is contained in:
1 parent
79119509a9
commit
22fba27145
555 files changed
+17342
-1394
No files matched your search
@@ -52,13 +52,30 @@ initialization of a binary array type, for backwards compatibility and so it doe
|
||||
The following code shows how to create a binary value.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/binary.cpp"
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a binary vector
|
||||
std::vector<std::uint8_t> vec = {0xCA, 0xFE, 0xBA, 0xBE};
|
||||
|
||||
// create a binary JSON value with subtype 42
|
||||
json j = json::binary(vec, 42);
|
||||
|
||||
// output type and subtype
|
||||
std::cout << "type: " << j.type_name() << ", subtype: " << j.get_binary().subtype() << std::endl;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/binary.output"
|
||||
type: binary, subtype: 42
|
||||
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
Reference in new issue
Block a user