001、将后台json字符串转换为json对象
1、剔除空格 tempData = dataStr.replace(/\s/ig, ' ');
2、转换 dataJson=eval('('+tempData+')');
002、为json对象动态添加属性
var params={};
params.wrongQuestionID=questionid;
//收集参数 function getJsonParams(){ var jsonParam={}; $("#form_selectQuestion input").each(function(index,dom){ jsonParam[dom.name]=dom.value; }); return jsonParam; }
003、序列化表单
json格式: data:$form.serializeArray(); 字符串方式:$form.serialize();
005、json_lib.jar
json排出多余属性
JsonConfig jsonConfig = new JsonConfig(); //建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略
/*此处是亮点,只要将所需忽略字段加到数组中即可,在上述案例中,所要忽略的是“libs”,
那么将其添到数组中即可,在实际测试中,我发现在所返回数组中,存在大量无用属性,
如“multipartRequestHandler”,“servletWrapper”,那么也可以将这两个加到忽略数组中.*/
jsonConfig.setExcludes(new String[]{"roles","parent","children", "functionurl",
"functionorder","scope","functionrel"});
JSONArray json=JSONArray.fromObject(rfs,jsonConfig);