-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadjson.cpp
61 lines (44 loc) · 1.64 KB
/
readjson.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
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
#include <array>
using json = nlohmann::json;
using namespace std;
int main(void) {
ifstream f("sort.json");
json data = json::parse(f);
json articlelist = data["listofarticles"];
int articlecounter = articlelist.size();
cout<<"Articles counted:";
cout<<articlecounter<<"\n";
// for (auto it = articlelist.begin(); it != articlelist.end(); ++it) {
// cout<<it.value()<<"\n";
// }
int counter1 = 0;
int counter2 = 0;
for (auto eid = articlelist.begin(); eid != articlelist.end(); ++eid)
{
json elem1 = articlelist[counter1];
counter1 +=1;
for (auto eid2 = articlelist.begin(); eid2 != articlelist.end(); ++eid2){
json elem = articlelist[counter2];
counter2 += 1;
cout<<elem<<"\n\n";
if (articlelist[counter2] == articlelist.size()-1)
{
cout<<" ";
}else
{
if (articlelist[counter2]["points"]<articlelist[counter2+1]["points"] )
{
json oldvalue1 = articlelist[counter2]["points"];
json oldvalue2 = articlelist[counter2+1]["points"];
articlelist[counter2] = oldvalue2;
articlelist[counter2+1] = oldvalue1;
}
}
}
counter2 = 0;
}
cout<<articlelist<<"\n===============\n";
}