How to Create a Restful service for a Huge JSON
data using Java eclipse Tomcat7.0
Hi every one ,.. I need need to create a Restful web service which
Is your Google down!!! There are a lots of good stuffs available in Google related with REST web-service.
Anyway Take a look at this stuff
Building a Simple RESTful Web Service to produce JSON using Jersey
Developing REST Web Services in Eclipse
For creating a JSON see this example
Say you want to create a JSON as shown below
{"subitem":
[{"rate":"123",
"baseitem":"148",
"item":"HIJ",
"section":"pub",
"imagename":"pic.png"
}],
"hoteltables":
[{"tableno":"123",
"status":"active",
"section":"pub",
"custid":"12"
}],
"mainiteam":
[{"status":"available",
"item":"ABC",
"itemid":"12",
"section":"pub",
"imagename":"XYZ"
}]
}
The java code for creating the above JSON is as given below
JSONArray obj = new JSONArray();
JSONObject jsonobj=new JSONObject();
HashMap rows=new HashMap();
rows.put("tableno","123");
rows.put("status","active");
rows.put("section","pub");
rows.put("custid","12");
obj.put(rows);
jsonobj.put("hoteltables", obj);
obj = new JSONArray();
rows=new HashMap();
rows.put("itemid","12");
rows.put("item","ABC");
rows.put("status","available");
rows.put("section","pub");
rows.put("imagename","XYZ");
obj.put(rows);
jsonobj.put("mainiteam", obj);
obj = new JSONArray();
rows=new HashMap();
rows.put("baseitem","148");
rows.put("item","HIJ");
rows.put("rate","123");
rows.put("section","pub");
rows.put("imagename","pic.png");
obj.put(rows);
jsonobj.put("subitem", obj);
System.out.println(jsonobj.toString());