This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RateJSONParser.java
106 lines (58 loc) · 2.2 KB
/
RateJSONParser.java
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
//package com.capmon;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
//import org.json.JSONarray;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class RateJSONParser {
public static String Rate(String Data) throws IOException {
JSONObject mainJson = new JSONObject(Data);
JSONArray loadArray = mainJson.getJSONArray("loads");
StringBuffer rateBuffer = new StringBuffer();
try {
/*
example for writing csv file
FileWriter writer = new FileWriter("test.csv");
writer.append("ID");
writer.append(',');
writer.append("name");
writer.append(',');
...
writer.append('\n');
writer.flush();
writer.close();
*/
// DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
// BufferedWriter curent = new BufferedWriter(new FileWriter("current.txt"));
// JSONObject childObject = loadArray.getJSONObject(0);
for(int i = 0; i < loadArray.length();i++){
JSONObject childObject = loadArray.getJSONObject(i);
String link = childObject.getString("link");
long rate = childObject.getLong("rate");
// curent.write(String.valueOf(rate));
// Date dateobj = new Date();
//rateBuffer.append((df.format(dateobj)));
//rateBuffer.append(",");
// System.out.println(df.format(dateobj));
//rateBuffer.append(link);
//rateBuffer.append(",");
// rateBuffer.append(df.format(dateobj));
//rateBuffer.append(",");
rateBuffer.append(rate);
rateBuffer.append(",");
// for adding date to the time stamp
// rateBuffer.append(" Bytes/Second : on Link : ");
// link = link.substring(36); /// truncating string from to start to remove http://....
// rateBuffer.append(link);
// rateBuffer.append("\r\n");
}
} catch (JSONException e) {
}
return rateBuffer.toString();
}
}