首先你的转义范围要先确定吧?
一般都是对中文、符号进行转义;
中文一般都是转成unicode;
如果数要转换成程序(JAVA)中直接使用的json字符串的话,一般都是在双引号前加\.
推荐给你一个json在线转义工具网页链接可以去看下。
字符串值编码为json字符串,"&"也被转义为"\".怎么禁止转换
这样的情况一般都是你的JSON不完整所致。在获取数据时这样处理一下就好了$.post(url,data,function(youjson){youjson=$.parseJSON(youjson);//然后继续处理你的代码就好了});
java json 被转义为怎么办
先做转义
不过,得看是怎样的具体的情况
java Json 串中的转义字符
一:解析普通json
1:不带转化字符
格式{"type":"ONLINE_SHIPS","message":{"currentTime":,"direction":0,"id":1,"latitude":29.,"longitude":.}}
JSONObjectjsonObject=newJSONObject(jsonstr).getJSONObject("message");
"currentTime:"+jsonObject.get("currentTime"));
"direction:"+jsonObject.get("direction"));
"latitude:"+jsonObject.get("latitude"));
"longitude:"+jsonObject.get("longitude"));
jsonarray
JSONObjectjo=ja.getJSONArray("cargoList").getJSONObject(0);
2:带转义字符的json格式
{"type":"ONLINE_SHIPS","message":"{\"currentTime\":,\"direction\":0,\"id\":1,\"latitude\":29.,\"longitude\":.}"}
其实也很简单,先把它转化成字符串就可以了
JSONObjectjsonObject=newJSONObject(jsonstr);
//先通过字符串的方式得到,转义字符自然会被转化掉
Stringjsonstrtemp=jsonObject.getString("message");
"message:"+jsonstrtemp);
jsonObject=newJSONObject(jsonstrtemp);
"currentTime:"+jsonObject.get("currentTime"));
"direction:"+jsonObject.get("direction"));
"latitude:"+jsonObject.get("latitude"));
"longitude:"+jsonObject.get("longitude"));
二:遍历Json对象
JSONObjectports=ja.getJSONObject("ports");
Iterator<String>keys=ports.keys();
while(keys.hasNext()){
Stringkey=keys.next();
Stringvalue=ports.getString(key);三:使用Gjson,json与对象相互转化
使用Gson轻松将java对象转化为json格式
Stringjson=gson.toJson(Object);//得到json形式的字符串
Useruser=gson.fromJson(json,User.class);//得到对象