2013年11月19日星期二

Json Chinese garbled

$. post to read out the data submitted by Chinese is garbled
action using the java array into jsonObject
JSONObject jo=JSONObject.fromObject(resultMap);out.print(jo.toString());

console output results
{"areas": [{"areaName": " Asia ", "areaId": 1}, {"areaName": " Europe ", "areaId": 2} , {"areaName": " American ", "areaId": 3}, {"areaName": " Africa ", "areaId": 4}, {"areaName": " Ocean State "," areaId ": 5}, {" areaName ":" ww "," areaId ": 6}, {" areaName ":" ee "," areaId ": 7}] , "type": [{"typeName": " action ", "typeDes": " play Video use ", "videoTypeId": 1}, {"typeName": " language " ;, "typeDes": " play Video use ", "videoTypeId": 2}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Highcharts Example</title>

<!-- 1. Add these JavaScript inclusions in the head of your page -->
<script type="text/javascript" src="<%=basePath %>/js/jquery.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="<%=basePath %>/js/highcharts.js" charset="UTF-8"></script>
<!--[if IE]>
<script type="text/javascript" src="../js/excanvas.compiled.js"></script>
<![endif]-->
<script type="text/javascript">
$(function(){
   $.post("../findJsonArea.action","",function(data){
           var dataObj = eval('('+data+')');    
           $('#area').empty();
           $('#type').empty();
           $('#area').append("<option value='0'>-----请选择-----</option>");
           $('#type').append("<option value='0'>-----请选择-----</option>");
      //alert(dataObj['areas'][0]['areaName']);
    $.each(dataObj['areas'],function(key,value){
     $('#area').append('<option value="'+value['areaId']+'">'+value['areaName']+'</option>');
    });
             $.each(dataObj['type'],function(key,value){
     $('#type').append('<option value="'+value['videoTypeId']+'">'+value['typeName']+'</option>');
    });           
          
   });

end of the show is a bunch of pages ? ? ? ?
. please a lot of guidance
------ Solution ------------------------------- -------------
not set header do ?
------ Solution ---------------------------------------- ----
first line and I'm sorry to tenth line . In this case, your character in the output from utf-8 transcoded to gb2312.
To avoid such frequent conversions , you can change the project default character set gb2312, then the first line should gb2312.
------ Solution ---------------------------------------- ----
Bangniding top Bangniding top
------ Solution ------------------------- -------------------
transmission , they also tostring look.
------ Solution ---------------------------------------- ----
then use the set up before you wear response code on it.
------ Solution ---------------------------------------- ----
response.setContentType ("text / html; charset = UTF-8/gbk / as you like it ");
------ Solution -------- ------------------------------------
upstairs . response settings look .
------ Solution ---------------------------------------- ----
are changed to UTF-8
gb2312 ">
------ Solution ------------------- -------------------------
+1
------ Solution ---------- ----------------------------------
Thank huh scores under every roof
------ Solution ---------------------------------------- ----
your page coding are inconsistent. . .
------ Solution ---------------------------------------- ----

- ----- Solution --------------------------------------------
page coding inconsistencies . Uniform encoding on the line .
------ Solution ---------------------------------------- ----
Why not apply a filter ?
------ Solution ---------------------------------------- ----
page coding inconsistencies . Uniform encoding on the line .        gb2312 nor are changed , ah, brother  
changed to UTF-8 try
------ Solution ----------------------------- ---------------

response.setContentType("text/html;charset=UTF-8");  
response.setCharacterEncoding("UTF-8");

Then your page

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

------ For reference only ----------------------------------- ----
technology stocks when I tell you , give you bonus ~
------ For reference only -------------------- -------------------
page coding inconsistencies . Uniform encoding on the line .   are changed gb2312 nor ah, brother
------ For reference only ------------------------ ---------------
filte do ? Used
------ For reference only ------------------------------------ ---
I have error correction method of the ~

没有评论:

发表评论