android HttpPost传JSON数据中文乱码的解决方法
来源:互联网 发布:mac有什么游戏 编辑:程序博客网 时间:2024/06/05 07:51
在项目中使用HttpPost方式向服务器提交JSON数据时,服务器上接收的json数据竟然显示乱码,查找了不少方法,最终一个解决了我的问题,我的部分代码如下:
HttpPost hp = new HttpPost(address);JSONObject jo = new JSONObject();try {jo.put("stationname", stationName);jo.put("personname", personName);jo.put("fileTime", fileTime);jo.put("filetype", fileType);System.out.println(jo);hp.setEntity(new StringEntity(jo.toString(), HTTP.UTF_8));hc.execute(hp);}
原代码中 hp.setEntity(jo.toString());不能正确的传输中文。改成这样:
hp.setEntity(new StringEntity(jo.toString(), HTTP.UTF_8));
要使用utf-8将请求参数进行编码后传输,在服务器端就能正确的读出json传输的中文字符了。
- android HttpPost传JSON数据中文乱码的解决方法
- Android HttpPost数据中文乱码的解决方案
- Android HttpPost数据中文乱码的解决方案
- HttpPost发送JSON数据中文乱码问题。
- HttpPost发送JSON数据中文乱码问题
- httpPost中文乱码解决方案(android)
- JSON遇到中文乱码问题的解决方法
- JSON遇到中文乱码问题的解决方法
- HttpPost+json请求---服务器中文乱码及其他
- HttpPost+json请求---服务器中文乱码及其他
- HttpPost 中文乱码。
- Spring MVC 对于返回JSON格式数据的中文乱码 解决方法
- ztree通过ajax加载json数据中文乱码的解决方法:springmvc配置
- 服务器回传的json数据中文乱码问题
- JSON数据的中文乱码问题
- 解决JSON数据的中文乱码问题
- JSON返回的数据中文乱码问题!!!
- JSON数据传递的中文乱码
- 用大括号初始化C++数据成员
- at指令集
- HDOJ 3657 - Game 构图最小割
- ubuntu:/opt/ecos/ecos-3.0/tools/bin# ./ecosconfig ./ecosconfig: error while loading shared lib
- Android 自动化测试—robotium(一)
- android HttpPost传JSON数据中文乱码的解决方法
- 初窥Linux 之 我最常用的20条命令
- Linux下搭建FTP服务器
- Linux下串口调试工具
- /etc/*release*
- poj 3686 The Windy's(最小权值和)
- Windows 8, EFI boot and dism image Capture and Apply method.
- 解决Oracle的Char只能读取第一个字符
- Java AES加密实现