-
Notifications
You must be signed in to change notification settings - Fork 3
/
jsonparse.java
28 lines (27 loc) · 1 KB
/
jsonparse.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
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.file.Files;
import java.nio.file.Paths;
class jsonparse
{
public static void main(String args[])
{
String file = "/cycolinks_textonly.json";
String json = readFileAsString(file);
json = json.substring(json.indexOf('{'),json.lastIndexOf(';')+1);
JSONObject baseJsonResponse = new JSONObject(json);
JSONObject d = baseJsonResponse.getJSONObject("d");
JSONObject b = d.getJSONObject("b");
JSONObject d2 = b.getJSONObject("d");
JSONObject coupons = d2.getJSONObject("coupons");
Map<String, JSONObject> map = (Map<String,JSONObject>)coupons.getMap();
ArrayList<String> list = new ArrayList<String>(map.keySet());
for(int i=0; i<list.size(); i++)
{
JSONObject code = coupons.getJSONObject(list.get(i));
if(code.getString("name")!="")
System.out.println("Code for "+code.getString("name")+" is : "+code.getString("code"));
}
}
}