var dataList = [];
var dataObject = "";
var row_limit = scopeView.paramsDataGrid.data.rows.length; // 查询条数
if (row_limit != 0) {
for (var no = 1; no <= row_limit; no++) {
var priceData = $('#price_id' + no).val();
dataObject={
'price' : priceData,
'operation_id' : myApp.mTransfer.fGet(scopeView.pConst.operation_id), //前画面跳转值
'toll_id' : scopeView.paramsDataGrid.data.rows[no-1][5] // 当前条的字段值
}
dataList[no-1] = dataObject;
}
myCrud.fUpdate({
resource : '路径'
isIgnoreForm : true,
data : {dataJson:JSON.stringify(dataList)}, // 转换JSON 字符串
onCompleted : function(result) {
scopeView.mEvaluate.MSG_2002410_FINISH.fShow(); //成功信息
scopeView.actionClose(); // 成功后关闭画面
},
isAsyncBusy : true
});
后端接收的json数组:
dataJson=[{price=11, operation_id=382761932419135, toll_id=88881}, {price=33, operation_id=382761932419135, toll_id=9999}]
//json转换为map
Map<String, Object> params = this.getRequestMapJSON(request);
JSONObject line=JSONObject.fromObject(params);
JSONArray paramList=line.getJSONArray("dataJson");
遍历
for(int i=0;i<paramList.size();i++){
toll_id = (String) paramList.getJSONObject(i).get("toll_id"); //取得json里的key值
}
public Map<String , Object> getRequestMapJSON(@Context HttpServletRequest request) {
Map<String, Object> paramMap = super.getRequestMap(request);
// JSONパーサー
ObjectMapper mapper = new ObjectMapper();
try {
// 運行指示をJSONから配列に変換
Object send = mapper.readValue(paramMap.get("dataJson").toString(), Object.class);
paramMap.put("dataJson", send);
} catch (IOException e) {
/ 変換エラーの場合は、セットしない。
}
return paramMap;
}
js端循环多条数据存入json数组
最新推荐文章于 2023-04-11 07:55:03 发布