forked from open-source-parsers/jsoncpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
39 lines (32 loc) · 896 Bytes
/
Copy pathmain.cc
File metadata and controls
39 lines (32 loc) · 896 Bytes
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
#include <cstdio>
#include <cstring>
#include <iostream>
// This is the JSON header
#include <json/json.h>
using namespace std;
int main(int argc, char **argv)
{
Json::Value fromScratch;
Json::Value array;
array.append("hello");
array.append("world");
fromScratch["hello"] = "world";
fromScratch["number"] = 2;
fromScratch["array"] = array;
fromScratch["object"]["hello"] = "world";
// write in a nice readible way
Json::StyledWriter styledWriter;
//std::cout << styledWriter.write(fromScratch);
// ---- parse from string ----
// write in a compact way
Json::FastWriter fastWriter;
std::string jsonMessage = fastWriter.write(fromScratch);
Json::Value parsedFromString;
Json::Reader reader;
bool parsingSuccessful = reader.parse(jsonMessage, parsedFromString);
if (parsingSuccessful)
{
std::cout << styledWriter.write(parsedFromString) << std::endl;
}
return 0;
}