FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
buckaroo-nholmann-json-example/main.cpp at master · njlr/buckaroo-nholmann-json-example · GitHub
njlr
buckaroo-nholmann-json-example
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
buckaroo-nholmann-json-example
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (36 loc) · 1.07 KB
Breadcrumbs
buckaroo-nholmann-json-example
/
main.cpp
Copy path
File metadata and controls
48 lines (36 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
include
<
nlohmann/json.hpp
>
using
namespace
nlohmann
;
int
main
() {
//
create an empty structure (null)
json j;
//
add a number that is stored as double (note the implicit conversion of j to an object)
j[
"
pi
"
] =
3.141
;
//
add a Boolean that is stored as bool
j[
"
happy
"
] =
true
;
//
add a string that is stored as std::string
j[
"
name
"
] =
"
Niels
"
;
//
add another null object by passing nullptr
j[
"
nothing
"
] =
nullptr
;
//
add an object inside the object
j[
"
answer
"
][
"
everything
"
] =
42
;
//
add an array that is stored as std::vector (using an initializer list)
j[
"
list
"
] = {
1
,
0
,
2
};
//
add another object (using an initializer list of pairs)
j[
"
object
"
] = { {
"
currency
"
,
"
USD
"
}, {
"
value
"
,
42.99
} };
//
instead, you could also write (which looks very similar to the JSON above)
json j2 = {
{
"
pi
"
,
3.141
},
{
"
happy
"
,
true
},
{
"
name
"
,
"
Niels
"
},
{
"
nothing
"
,
nullptr
},
{
"
answer
"
, {
{
"
everything
"
,
42
}
}},
{
"
list
"
, {
1
,
0
,
2
}},
{
"
object
"
, {
{
"
currency
"
,
"
USD
"
},
{
"
value
"
,
42.99
}
}}
};
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL