`

JSON的问题

    博客分类:
  • AJAX
阅读更多
今天想利用json写一个tree,但是中途碰到一个关于单引号,双引号的问题,折磨了我两个小时,特此写下,记录这事,

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("attributes", "{id:\"node2_value\"}, rel:\"adm\"}");
		map.put("data", "机构\"名称");
		map.put("icons", "../images/tree/hd.png");
		map.put("state", "open");
		JSONObject json = JSONObject.fromObject(map);

		response.getWriter().write(json.toString());



传到前台的竟是
{"icons":"../images/tree/hd.png","attributes":"{id:\"node2_glue\"}, rel:\"adm\"}","data":"机构\"名称","state"
:"open"}
后来把\"换成' ,但只json标准又不支持'.

最后终于转过来劲了 ,晕死这么简单

		Map<String, Object> map = new HashMap<String, Object>();

		Map<String, Object> sMap = new HashMap<String, Object>();

		sMap.put("id", "node2_value");
		sMap.put("rel", "adm");
		map.put("attributes", sMap);
		map.put("data", "机构\"名称");
		map.put("icons", "../images/tree/hd.png");
		map.put("state", "open");
		JSONObject json = JSONObject.fromObject(map);


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics