我们使用 Ajax 从 UI 发送 JSON 数据:
$.ajax({
url: "/RegisterUser",
type: "POST",
Contenttype: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(formData),
success: function(data, textStatus, xhr)
{
alert(data);
}
});
@RequestMapping(value="/RegisterUser", method = RequestMethod.POST)
public ServiceResponse registerUser(
@RequestBody String UserDetails) {
logger.info("JSON DATA"+UserDetails);
}
但是,来自webservice的数据带有特殊字符,如何处理?
%7B%22Test%22%3A%7B%22Test11%22%3A%22Test%22%2C%22name%22%3A%22Test11%22%2C%22email%22%3A%22Test%40gmail.com%22%7D%2C%22Details%22%3A%7B%22date_of_brith%22%3A%2205%2F01%2F2015%22%2C%22gender%22%3A%22Male%22%2C%22
如何将数据解码/转义为字符串?
这看起来像 application/x-www-form-urlencoded
数据。
尝试并使用:
final String decoded = URLDecoder.decode(encoded, "UTF-8");
我是一名优秀的程序员,十分优秀!