对象生成JSON的方式

public String getResult(Object ob,Object Top,Object TopBody){JSONObject jtop = new JSONObject();try {Class c1 = Top.getClass();Field[] fi = c1.getDeclaredFields();for(int i = 1; i<fi.length;i++){fi[i].setAccessible(true);jtop.put(fi[i].getName(), fi[i].get(Top));}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}JSONObject jt = new JSONObject();try {Class c1 = TopBody.getClass();Field[] fi = c1.getDeclaredFields();for(int i = 1; i<fi.length;i++){fi[i].setAccessible(true);jt.put(fi[i].getName(), fi[i].get(TopBody));}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}jtop.put("client_message", jt);JSONObject json = new JSONObject();//创建json格式的数据try {Class c1 = ob.getClass();Field[] fi = c1.getDeclaredFields();for(int i = 1; i<fi.length;i++){fi[i].setAccessible(true);json.put(fi[i].getName(), fi[i].get(ob));}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}jtop.put("data",json);String result = HttpRequest.sendPost(UserUrl, "message="+jtop.toString());return result;}

,刺是与生俱来的,上帝在赐予优越感同时捆-绑的附属品;

对象生成JSON的方式

相关文章:

你感兴趣的文章:

标签云: