Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
7724d347
Commit
7724d347
authored
Jan 18, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed #31: only use spaces in pretty print
parent
b30e9ee5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
13 deletions
+13
-13
README.md
README.md
+1
-3
header_only/json.h
header_only/json.h
+5
-4
src/json.cc
src/json.cc
+5
-4
test/json_unit.cc
test/json_unit.cc
+2
-2
No files found.
README.md
View file @
7724d347
...
...
@@ -132,7 +132,7 @@ You can also get a string representation (serialize):
```
cpp
// explicit conversion to string
std
::
string
s
=
j
.
dump
();
// {\"happy\":
true, \"pi\":
3.141}
std
::
string
s
=
j
.
dump
();
// {\"happy\":
true,\"pi\":
3.141}
// serialization with pretty printing
std
::
cout
<<
j
.
dump
(
4
)
<<
std
::
endl
;
...
...
@@ -142,8 +142,6 @@ std::cout << j.dump(4) << std::endl;
// }
```
The value of s could be
`{"pi": 3.141, "happy": true}`
, but the order of the entries in the object is not fixed.
You can also use streams to serialize and deserialize:
```
cpp
...
...
header_only/json.h
View file @
7724d347
...
...
@@ -982,7 +982,7 @@ std::string json::dump(const bool prettyPrint, const unsigned int indentStep,
{
if
(
i
!=
value_
.
array
->
begin
())
{
result
+=
prettyPrint
?
",
\n
"
:
",
"
;
result
+=
prettyPrint
?
",
\n
"
:
","
;
}
result
+=
indent
()
+
i
->
dump
(
prettyPrint
,
indentStep
,
currentIndent
);
}
...
...
@@ -1017,10 +1017,11 @@ std::string json::dump(const bool prettyPrint, const unsigned int indentStep,
{
if
(
i
!=
value_
.
object
->
begin
())
{
result
+=
prettyPrint
?
",
\n
"
:
",
"
;
result
+=
prettyPrint
?
",
\n
"
:
","
;
}
result
+=
indent
()
+
"
\"
"
+
i
->
first
+
"
\"
: "
+
i
->
second
.
dump
(
prettyPrint
,
indentStep
,
currentIndent
);
result
+=
indent
()
+
"
\"
"
+
i
->
first
+
"
\"
:"
+
(
prettyPrint
?
" "
:
""
)
+
i
->
second
.
dump
(
prettyPrint
,
indentStep
,
currentIndent
);
}
// decrease indentation
...
...
src/json.cc
View file @
7724d347
...
...
@@ -530,7 +530,7 @@ std::string json::dump(const bool prettyPrint, const unsigned int indentStep,
{
if
(
i
!=
value_
.
array
->
begin
())
{
result
+=
prettyPrint
?
",
\n
"
:
",
"
;
result
+=
prettyPrint
?
",
\n
"
:
","
;
}
result
+=
indent
()
+
i
->
dump
(
prettyPrint
,
indentStep
,
currentIndent
);
}
...
...
@@ -565,10 +565,11 @@ std::string json::dump(const bool prettyPrint, const unsigned int indentStep,
{
if
(
i
!=
value_
.
object
->
begin
())
{
result
+=
prettyPrint
?
",
\n
"
:
",
"
;
result
+=
prettyPrint
?
",
\n
"
:
","
;
}
result
+=
indent
()
+
"
\"
"
+
i
->
first
+
"
\"
: "
+
i
->
second
.
dump
(
prettyPrint
,
indentStep
,
currentIndent
);
result
+=
indent
()
+
"
\"
"
+
i
->
first
+
"
\"
:"
+
(
prettyPrint
?
" "
:
""
)
+
i
->
second
.
dump
(
prettyPrint
,
indentStep
,
currentIndent
);
}
// decrease indentation
...
...
test/json_unit.cc
View file @
7724d347
...
...
@@ -1921,8 +1921,8 @@ TEST_CASE("Parser")
{
auto
j23
=
"{
\"
a
\"
: null,
\"
b
\"
: true,
\"
c
\"
: [1,2,3],
\"
d
\"
: {
\"
a
\"
: 0} }"
_json
;
CHECK
(
j23
.
dump
()
==
"{
\"
a
\"
:
null,
\"
b
\"
: true,
\"
c
\"
: [1, 2, 3],
\"
d
\"
: {
\"
a
\"
:
0}}"
);
CHECK
(
j23
.
dump
(
-
1
)
==
"{
\"
a
\"
:
null,
\"
b
\"
: true,
\"
c
\"
: [1, 2, 3],
\"
d
\"
: {
\"
a
\"
:
0}}"
);
CHECK
(
j23
.
dump
()
==
"{
\"
a
\"
:
null,
\"
b
\"
:true,
\"
c
\"
:[1,2,3],
\"
d
\"
:{
\"
a
\"
:
0}}"
);
CHECK
(
j23
.
dump
(
-
1
)
==
"{
\"
a
\"
:
null,
\"
b
\"
:true,
\"
c
\"
:[1,2,3],
\"
d
\"
:{
\"
a
\"
:
0}}"
);
CHECK
(
j23
.
dump
(
0
)
==
"{
\n\"
a
\"
: null,
\n\"
b
\"
: true,
\n\"
c
\"
: [
\n
1,
\n
2,
\n
3
\n
],
\n\"
d
\"
: {
\n\"
a
\"
: 0
\n
}
\n
}"
);
CHECK
(
j23
.
dump
(
4
)
==
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment