How to create restful web services for JSON data in Java, Tomcat and eclipse
•
Java
I have a JSON data like this I want to create a restful web service that generates a JSON output, just like the link above
I saw how to create a restful service for a huge JSON data using java eclipse tomcat7 0
I would like to add to the above conditions:
{
status: "ok",count: 10,pages: 6,category:{
The previous answer was this
{
category:{/[
I'll take this
{
status: "ok",category:{
Solution
Look at this answer
A typical JSON is shown below
{
"name":"Ersin","surname":"Çetinkaya","age":"25","address":[{"city": "Bursa","country": "Türkiye","zipCode": "33444"}],"phones": ["234234242","345345354"]
}
The Java code used to create the above JSON is given below
public JSONObject getValues()
{
JSONObject jsonobj=new JSONObject();
jsonobj.put("name","Ersin");
jsonobj.put("surname","Çetinkaya");
jsonobj.put("age","25");
JSONArray obj = new JSONArray();
HashMap rows=new HashMap();
rows.put("city","Bursa");
rows.put("country","Türkiye");
rows.put("zipCode","33444");
obj.put(rows);
jsonobj.put("address",obj);
JSONArray phobj = new JSONArray();
phobj.put("234234242");
phobj.put("345345354");
jsonobj.put("phones",phobj);
System.out.println(jsonobj.toString());
return jsonobj.toString();
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
