JSONObject转化为数组,方便前台数据遍历

1、效果图

JSONObject转化为数组,方便前台数据遍历

JSONObject转化为数组,方便前台数据遍历

2、核心代码


for (ClsScore jStr : cls) {
				JSONObject jClsScore1 = (JSONObject) JSONArray.toJSON(jStr);
				// 获取学科成绩JSON
				String strClsScore = jClsScore1.getString("clsXkScoreAndRank");
				if (strClsScore == null || strClsScore.isEmpty())
					continue;
				JSONObject jclsScore = JSON.parseObject(strClsScore);
				Object ClsScore[] = new Object[34];
				int i = 0;
			for (int xk =1; xk < 9; xk++ ) {

				JSONObject xkScore = null;
				if(jclsScore.getJSONObject(""+xk) != null){
					xkScore  = jclsScore.getJSONObject(""+xk);
				}
				if(xk == 1 || xk == 2 || xk == 3){
				
					if (xkScore == null || xkScore.isEmpty()) {
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						
					} else {
						ClsScore[i++] = xkScore.getString("master");
						ClsScore[i++] = xkScore.getDoubleValue("stuScore");
						ClsScore[i++] = xkScore.getDoubleValue("stuGradeRank");
						
					}
				
				}else{
					if (xkScore == null || xkScore.isEmpty()) {
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						
					} else if (xkScore.getDoubleValue("stuScore1") == 0){
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						ClsScore[i++] = -1;
						
					}else{
						ClsScore[i++] = xkScore.getString("master");
						ClsScore[i++] = xkScore.getDoubleValue("stuScore");
						ClsScore[i++] = xkScore.getDoubleValue("stuGradeRank");
						ClsScore[i++] = xkScore.getDoubleValue("stuScore1");
						ClsScore[i++] = xkScore.getDoubleValue("stuGradeRank1");
					}
					
				}
			}
			jClsScore1.put("scores", ClsScore);
			jInfo.add(jClsScore1);
			}


<tbody>
                <%_.each(data, function(d){%>
                <tr>
                    <% if(d.className=="-1"){%>
                    <td style="color:#ddd;background-color:#ddd;"> </td>
                    <%}else{%>
                    <td><%=d.className%></td>
                    <%}%>
                    <td><%=d.stuCount%></td>
                    <td><%=d.clsSvg%></td>
                    <% if(d.clsRank==9999){%>
                        <td style="color:#ddd;background-color:#ddd;"><%=d.clsRank%></td>
                    <%}else{%>
                        <td><%=d.clsRank%></td>
                    <%}%>
                    <td><%=d.clsSvg1%></td>
                    <% if(d.clsRank1==9999){%>
                        <td style="color:#ddd;background-color:#ddd;"><%=d.clsRank%></td>
                    <%}else{%>
                        <td><%=d.clsRank1%></td>
                    <%}%>
                    <%_.each( d.scores, function(ds){%>

                        <% if(ds=="-1"){%>
                        <td style="color:#ddd;background-color:#ddd;"> </td>
                        <%