通过Json格式将数据传给服务端

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xgysimida/article/details/78566854

1、导入json相关的jar包,一共是6个,如果有需要jar包的欢迎大家私聊我!


2、在继承HttpServlet类下面的doGet()方法中写如下的程序

                request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");

                 PrintWriter out = response.getWriter(); 
//下面的是用json传数据
JSONObject jsonback = new JSONObject();

jsonback.put("Streetcode", rs.getInt("Streetcode"));
jsonback.put("Lightnumber", rs.getInt("Lightnumber"));
jsonback.put("Currbright", rs.getString("Currbright"));
jsonback.put("Temperature", rs.getString("Temperature"));
jsonback.put("Humidity", rs.getString("Humidity"));

out.print(jsonback);




    通过启动tomcat服务器测试,发现解析的数据格式正好是Json的格式,希望大家采纳!!!


展开阅读全文

如何通过vc将实时采集的数据传给Excel?

07-24

对于静态的数据写入excel,已经可以实现了。rn我用的是msdn上的一个例子。rn _Application app;rn Workbooks oBooks; _Workbook oBook;rn Worksheets oSheets; _Worksheet oSheet;rn Range oRange;rn LPDISPATCH lpDisp;rn rn // Define some common OLE variants.rn COleVariant covTrue((short)TRUE), covFalse((short)FALSE);rn COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);rn rn // Now, We start Excel and get the Application object.rn if (!app.CreateDispatch("Excel.Application"))rn rn AfxMessageBox("不能启动Excel以得到应用程序对象!");rn return;rn rn app.SetVisible(TRUE); // Set visiblernrn // 得到工作簿集rn lpDisp = app.GetWorkbooks(); rn ASSERT(lpDisp);rn oBooks.AttachDispatch(lpDisp);rnrn // 打开一个已有的工作簿rn lpDisp = oBooks.Open("E:\\Test", rn covOptional,covOptional,covOptional,covOptional,rn covOptional,covOptional,covOptional,covOptional,rn covOptional,covOptional,covOptional,covOptional,rn covOptional,covOptional); rn ASSERT(lpDisp);rn oBook.AttachDispatch(lpDisp);rnrn // 得到表单集rn lpDisp = oBook.GetSheets();rn ASSERT(lpDisp);rn oSheets.AttachDispatch(lpDisp);rn rn // 得到第一张表单rn lpDisp = oSheets.GetItem(COleVariant((short)1));rn ASSERT(lpDisp);rn oSheet.AttachDispatch(lpDisp);rn         rn         // 写入静态的数据rn         lpDisp = oSheet.GetRange(COleVariant("A1"),COleVariant("A1"));rn oRange.AttachDispatch(lpDisp);rn oRange.SetHorizontalAlignment(COleVariant((short)3));rn oRange.SetValue2(COleVariant("X"));rn lpDisp = oSheet.GetRange(COleVariant("B1"),COleVariant("B1"));rn oRange.AttachDispatch(lpDisp);rn oRange.SetHorizontalAlignment(COleVariant((short)3));rn oRange.SetValue2(COleVariant("Y"));rnrn // 怎样每隔一段时间读取数据,并写入到Excel中呢?rnrnrn}rn现在想隔一段固定时间从数据文件中读取一个数据,rn然后将这个数据增添到Excel表格中。rn 论坛

没有更多推荐了,返回首页