如何使用Java eclipse Tomcat7.0为巨大的JSON
数据创建Restful服务
大家好,.. 我需要创建一个Restful Web服务来获取Json数据,..
包含Json数组的Json数据,...我需要在eclipse中使用Tomcat和java执行此操作,.. 如果可能的话,给我一个关于Big Json数据的教程,...... 三江源,
答案 0 :(得分:0)
您的Google是否已关闭!!! Google提供了许多与REST网络服务相关的好东西。
无论如何看看这个东西
<强> Building a Simple RESTful Web Service to produce JSON using Jersey 强>
<强> Developing REST Web Services in Eclipse 强>
要创建JSON,请参阅此示例
假设您要创建一个JSON,如下所示
{"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"
}]
}
用于创建上述JSON的java代码如下所示
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());