mirror of
https://github.com/nlohmann/json.git
synced 2026-03-24 18:02:47 +00:00
Documentation change (#3672)
Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
This commit is contained in:
@@ -14,8 +14,8 @@ noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_
|
||||
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
|
||||
```
|
||||
|
||||
This function is usually called by the [`get()`](../basic_json/get.md) function of the
|
||||
[basic_json](../basic_json) class (either explicit or via conversion operators).
|
||||
This function is usually called by the [`get()`](../basic_json/get.md) function of the [basic_json](../basic_json)
|
||||
class (either explicitly or via the conversion operators).
|
||||
|
||||
1. This function is chosen for default-constructible value types.
|
||||
2. This function is chosen for value types which are not default-constructible.
|
||||
@@ -32,9 +32,41 @@ This function is usually called by the [`get()`](../basic_json/get.md) function
|
||||
|
||||
Copy of the JSON value, converted to `ValueType`
|
||||
|
||||
!!! note
|
||||
## Examples
|
||||
|
||||
This documentation page is a stub.
|
||||
??? example "Example: (1) Default-constructible type"
|
||||
|
||||
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is
|
||||
called by the `adl_serializer` when `get<ns::person>()` is called.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/from_json__default_constructible.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/from_json__default_constructible.output"
|
||||
```
|
||||
|
||||
??? example "Example: (2) Non-default-constructible type"
|
||||
|
||||
The example below shows how a `from_json` is implemented as part of a specialization of the `adl_serializer` to
|
||||
realize the conversion of a non-default-constructible type.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/from_json__non_default_constructible.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/from_json__non_default_constructible.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [to_json](to_json.md)
|
||||
|
||||
## Version history
|
||||
|
||||
|
||||
@@ -17,9 +17,26 @@ This function is usually called by the constructors of the [basic_json](../basic
|
||||
`val` (in)
|
||||
: value to read from
|
||||
|
||||
!!! note
|
||||
## Examples
|
||||
|
||||
This documentation page is a stub.
|
||||
??? example
|
||||
|
||||
The example below shows how a `to_json` function can be implemented for a user-defined type. This function is called
|
||||
by the `adl_serializer` when the constructor `basic_json(ns::person)` is called.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/to_json.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/to_json.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [from_json](from_json.md)
|
||||
|
||||
## Version history
|
||||
|
||||
|
||||
Reference in New Issue
Block a user