java - Convert HttpServletRequest to JSON as "UTF-8" -
i have method, converts httpservletrequest
json format:
public jsonobject requesttojson(httpservletrequest request){ stringbuffer jb = new stringbuffer(); string line = null; try { bufferedreader reader = request.getreader(); while ((line = reader.readline()) != null) jb.append(line); } catch (exception e) { /*report error*/ } return new jsonparser().parse(jb.tostring()).getasjsonobject(); }
the problem is, how convert request "utf-8" encoding?
updated: checked, default reader takes request "iso-8859-1". how set parameter reader, took "utf-8".
i found solution myself. added top:
request.setcharacterencoding("utf-8");
Comments
Post a Comment