如何通过“&” json格式的符号。
输入在这里,
JSON:
{
"sid":"sid2",
"password":"a&b",
"sec_type":"2"
}
在此期间我正在形成json
,密码字段'a& b'会在发送前自动转换为'\ u0026'。这让我陷入了困境。
我使用tojson()方法转换了模型。
答案 0 :(得分:0)
如果您正在使用Gson
,那么
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
gson.toJson(yourObject);
应该这样做。
答案 1 :(得分:0)
我通过以下格式解决了这个问题。谢谢大家.. :)
JSONObject jsonObject= new JSONObject();
try {
jsonObject.put("ssid", getID());
jsonObject.put("password", a&b());
jsonObject.put("sec_type", getSecType());
return jsonObject.toString();
} catch (JSONException e) {
e.printStackTrace();
return "";
}
现在它显然正是我发送的内容