大家好,又见面了,我是你们的朋友全栈君。
[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 getMessage(String msg) {
HashMap map = new HashMap();
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 userMap = new HashMap();
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 getCoord(String msg){
//HashMap map = new HashMap();
//String[] msgString = msg.toString().split(“_”);
//map.put(“x”, msgString[0]);
//map.put(“x”, msgString[1]);
//return map;
//}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151287.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...