-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonR.cpp
109 lines (73 loc) · 1.85 KB
/
JsonR.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include"JSONR.h"
using namespace std;
JSONR::JSONR(string filename)
{
this->JSON.open(filename+".json",std::fstream::out);
this->JSON<<"{"<<endl;
}
void JSONR::compileJSON()
{
for(int i=0;i<this->compiler.size();i++)
{
if(i==this->compiler.size()-1)
this->JSON<<this->compiler[i]<<"\n";
else
this->JSON<<this->compiler[i]<<", \n";
}
}
void JSONR::closeJSON()
{
this->JSON<<"}";
this->JSON.close();
}
void JSONR::addInteger(string key,string value)
{
this->compiler.push_back(this->quote+key+this->quote+":"+value);
}
void JSONR::addString(string key,string value)
{
this->compiler.push_back(this->quote+key+this->quote+":"+this->quote+value+this->quote);
}
void JSONR::addBool(string key,string value)
{
if(value!="false" && value !="true")
this->compiler.push_back( " \" error \": \"invalid boolean format \" ");
else
this->compiler.push_back(this->quote+key+this->quote+":"+this->quote+value+this->quote);
}
void JSONR::addArray(string key,string array[],int size)
{
string array_values;
for(int i=0;i<size;i++)
{
if(i==size-1)
array_values+=array[i];
else
array_values+=array [i]+",";
}
this->compiler.push_back(this->quote+key+this->quote+":"+this->quote+"["+array_values+"]"+this->quote);
}
void JSONR::addObject(string key,string keys[],string values[],int sizeKey,int sizeVal)
{
string key_values;
string array_values;
string relationship_final;
for(int i=0;i<sizeKey;i++)
{
key_values = keys[i];
array_values = values[i];
if(i==sizeVal-1)
{
relationship_final.append(key_values+":"+array_values);
}
else
{
relationship_final.append(key_values+":"+array_values+",");
}
}
this->compiler.push_back(this->quote+key+this->quote+":"+this->quote+"{"+relationship_final+"}"+this->quote);
}