简体   繁体   English

如何在JSON API中传递“&”符号

[英]How to pass “&” Symbol in json API

How to pass the "&" symbol in json format. 如何以json格式传递“&”符号。

Input is here, 输入在这里,

json: 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. 在这种情况下,当我形成json ,密码字段“ a&b”在发送前会自动转换为“ \\ u0026”。 It takes me into a issue. 它把我带入一个问题。

I converted the model using tojson() method. 我使用tojson()方法转换了模型。

If you're using Gson , then 如果您使用的是Gson ,那么

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 现在很明显我发送了什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM