Java escape JSON String?
我有以下JSON字符串,我正在发送到NodeJS服务器:
String string = "{\"id\":\"" + userID + "\",\"type\":\"" + methoden + "\",\"msg\":\"" + msget + "\", \"name\":\"" + namnet + "\", \"channel\":\"" + activeChatChannel + "\", \"visitorNick\":\"\", \"agentID\":\" " + agentID + "\"}";
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "utf-8"));
pw.println(string);
当字符串包含字符和msget
"
'
在NodeJS服务器上,我正在解析JSON,如下所示:
var obj = JSON.parse(message);
任何想法,我怎么能设法发送所有字符没有问题?