mirror of
https://github.com/nlohmann/json.git
synced 2026-06-18 18:34:17 +00:00
Use get instead of template get in REAMD.md and docs in non-template context (#4846)
Signed-off-by: Andy Choi <ccpong516@gmail.com>
This commit is contained in:
@@ -37,7 +37,7 @@ Copy of the JSON value, converted to `ValueType`
|
||||
??? 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 `template get<ns::person>()` is called.
|
||||
called by the `adl_serializer` when `get<ns::person>()` is called.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/from_json__default_constructible.cpp"
|
||||
|
||||
@@ -53,7 +53,7 @@ The default value is `0`.
|
||||
const json j = Choice::first;
|
||||
|
||||
// normally invokes from_json parse function but with JSON_DISABLE_ENUM_SERIALIZATION defined, it does not
|
||||
Choice ch = j.template get<Choice>();
|
||||
Choice ch = j.get<Choice>();
|
||||
}
|
||||
```
|
||||
|
||||
@@ -86,7 +86,7 @@ The default value is `0`.
|
||||
const json j = Choice::first;
|
||||
|
||||
// uses user-defined from_json function defined by macro
|
||||
Choice ch = j.template get<Choice>();
|
||||
Choice ch = j.get<Choice>();
|
||||
}
|
||||
```
|
||||
|
||||
@@ -109,7 +109,7 @@ The default value is `0`.
|
||||
|
||||
void from_json(const json& j, Choice& ch)
|
||||
{
|
||||
auto value = j.template get<std::string>();
|
||||
auto value = j.get<std::string>();
|
||||
if (value == "first")
|
||||
{
|
||||
ch = Choice::first;
|
||||
@@ -122,7 +122,7 @@ The default value is `0`.
|
||||
|
||||
void to_json(json& j, const Choice& ch)
|
||||
{
|
||||
auto value = j.template get<std::string>();
|
||||
auto value = j.get<std::string>();
|
||||
if (value == "first")
|
||||
{
|
||||
ch = Choice::first;
|
||||
@@ -139,7 +139,7 @@ The default value is `0`.
|
||||
const json j = Choice::first;
|
||||
|
||||
// uses user-defined from_json function
|
||||
Choice ch = j.template get<Choice>();
|
||||
Choice ch = j.get<Choice>();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ By default, implicit conversions are enabled.
|
||||
|
||||
```cpp
|
||||
json j = "Hello, world!";
|
||||
auto s = j.template get<std::string>();
|
||||
auto s = j.get<std::string>();
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
@@ -37,7 +37,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
|
||||
!!! important "Important notes"
|
||||
|
||||
- When using [`template get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will default to the first specified
|
||||
- When using [`get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will default to the first specified
|
||||
conversion. Select this default pair carefully. See example 1 below.
|
||||
- If an enum or JSON value is specified in multiple conversions, the first matching conversion from the top of the
|
||||
list will be returned when converting to or from JSON. See example 2 below.
|
||||
|
||||
Reference in New Issue
Block a user