🐛 fixed README example
The example with the size() operator is bad: using operator[] already changes the size of the object. The fix makes it clearer.
This commit is contained in:
parent
e2f6cf7f46
commit
951d0920fc
2 changed files with 3 additions and 28 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
|
#include <iomanip> // for std::setw
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
@ -29,7 +30,8 @@ int main()
|
||||||
j["new"]["key"]["value"] = {"another", "list"};
|
j["new"]["key"]["value"] = {"another", "list"};
|
||||||
|
|
||||||
// count elements
|
// count elements
|
||||||
j["size"] = j.size();
|
auto s = j.size();
|
||||||
|
j["size"] = s;
|
||||||
|
|
||||||
// pretty print with indent of 4 spaces
|
// pretty print with indent of 4 spaces
|
||||||
std::cout << std::setw(4) << j << '\n';
|
std::cout << std::setw(4) << j << '\n';
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
{
|
|
||||||
"answer": {
|
|
||||||
"everything": 42
|
|
||||||
},
|
|
||||||
"happy": true,
|
|
||||||
"list": [
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
2
|
|
||||||
],
|
|
||||||
"name": "Niels",
|
|
||||||
"new": {
|
|
||||||
"key": {
|
|
||||||
"value": [
|
|
||||||
"another",
|
|
||||||
"list"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nothing": null,
|
|
||||||
"object": {
|
|
||||||
"currency": "USD",
|
|
||||||
"value": 42.99
|
|
||||||
},
|
|
||||||
"pi": 3.141,
|
|
||||||
"size": 9
|
|
||||||
}
|
|
Loading…
Reference in a new issue