[java]代码库
package com.smartAnji.control.utils;
import java.util.HashMap;
public class MessageUtil {
public final static String TYPE = "type";
public final static String DATA = "data";
public final static String MESSAGE = "message";
public final static String COORD = "coord";
public final static String BEGIN = "begin";
public final static String USER = "user";
public static HashMap<String,String> getMessage(String msg) {
HashMap<String,String> map = new HashMap<String,String>();
String msgString = msg.toString();
String m[] = msgString.split(",");
map.put("fromName", m[0]);
map.put("toName", m[1]);
map.put("content", m[2]);
map.put("type", m[3]);
return map;
}
public static String sendContent(String type, Object mapContent) {
Map<String,Object> userMap = new HashMap<String,Object>();
userMap.put(MessageUtil.TYPE, type);
userMap.put(MessageUtil.DATA, mapContent);
// Map转JSON字符串
Gson gson = new Gson();
String jsonMsg = gson.toJson(userMap);
return jsonMsg;
}
// public static HashMap<String,String> getCoord(String msg){
// HashMap<String,String> map = new HashMap<String,String>();
// String[] msgString = msg.toString().split("_");
// map.put("x", msgString[0]);
// map.put("x", msgString[1]);
// return map;
// }
}
by: 发表于:2017-08-29 16:25:12 顶(0) | 踩(0) 回复
??
回复评论