How to pass the "&" symbol in json format.
Input is here,
json:
{
"sid":"sid2",
"password":"a&b",
"sec_type":"2"
}
In this while i am forming json
, password field 'a&b' is automatically converted into '\&' before sending. It takes me into a issue.
I converted the model using tojson() method.
If you're using Gson
, then
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
gson.toJson(yourObject);
should do the trick.
I solved this by below format. Thanks all..:)
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 "";
}
Now it clearly going exactly what i sent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.