日期:2014-05-16 浏览次数:20403 次
jQuery("#table").jqGrid({ datatype: "json", width:1019, colNames:['编号','名称'], colModel:[ {name:'no',index:'no', width:15, editable:false}, {name:'name',index:'name', width:15, sortable:false,editable: true} ], multiselect: false, cellEdit:true, cellsubmit:"clientArray", caption: "数据列表" , onSelectRow: function(ids) { s=ids; } });
function getFormJosn(){ var tmp=[]; var Data=""; $("#table>tbody>tr").each(function (){ tmp[this.id] = "{'no':'"+$("#table").getRowData(this.id).no+"',"; tmp[this.id] += "'name':'"+$("#table").getRowData(this.id).name+"'}"; }); for(var n =0;n<tmp.length;n++){ Data+=tmp[n]; Data+=","; } return {'Data':Data}; }
//保存 $("#doSave").click(function(){ var Data=""; Data= getFormJosn(); $.ajax({ type: 'POST', url:"xxxx.action?doSave", data: Data, success:function(data){ alert("over"); } }); });
public class JsonProvider { public static String writeToString(Object object){ String result =""; try { ObjectMapper m = new ObjectMapper(); result =m.writeValueAsString(object); } catch (JsonGenerationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result ; } public static TypeData fromJSON(String json, TypeData clazz) { ObjectMapper mapper = new ObjectMapper(); try { clazz= mapper.readValue(json, TypeData.class); } catch (JsonGenerationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return clazz; } public static void main(String[] args) { //resolveJson(); String json="{\"name\":\"张三\",\"年龄\":\"15\"}"; fromJSON(json,new TypeData()); } }