mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
📝 updated documentation for update() function #661
This commit is contained in:
17
doc/examples/update.cpp
Normal file
17
doc/examples/update.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create two JSON objects
|
||||
json o1 = R"( {"color": "red", "price": 17.99} )"_json;
|
||||
json o2 = R"( {"color": "blue", "speed": 100} )"_json;
|
||||
|
||||
// add all keys from o2 to o1 (updating "color")
|
||||
o1.update(o2);
|
||||
|
||||
// output updated object o1
|
||||
std::cout << std::setw(2) << o1 << '\n';
|
||||
}
|
1
doc/examples/update.link
Normal file
1
doc/examples/update.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/ZmHD2plm6OAuY6uJ"><b>online</b></a>
|
5
doc/examples/update.output
Normal file
5
doc/examples/update.output
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"color": "blue",
|
||||
"price": 17.99,
|
||||
"speed": 100
|
||||
}
|
17
doc/examples/update__range.cpp
Normal file
17
doc/examples/update__range.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create two JSON objects
|
||||
json o1 = R"( {"color": "red", "price": 17.99} )"_json;
|
||||
json o2 = R"( {"color": "blue", "speed": 100} )"_json;
|
||||
|
||||
// add all keys from o2 to o1 (updating "color")
|
||||
o1.update(o2.begin(), o2.end());
|
||||
|
||||
// output updated object o1
|
||||
std::cout << std::setw(2) << o1 << '\n';
|
||||
}
|
1
doc/examples/update__range.link
Normal file
1
doc/examples/update__range.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/Dg4mswDmYr4e0M4f"><b>online</b></a>
|
5
doc/examples/update__range.output
Normal file
5
doc/examples/update__range.output
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"color": "blue",
|
||||
"price": 17.99,
|
||||
"speed": 100
|
||||
}
|
Reference in New Issue
Block a user