JSON数据转换成table表格
<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%
String path =request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath %>js/jquery-1.9.1.js"></script> <style type="text/css">
.table-result{
width:100%;
border:1px solid #f2f2f2;
text-align:left;
border-collapse: collapse;
}
.table-result th{
height:40px;
font-weight: normal;
font-size:14px;
line-height:22px;
text-align:center;
background-color:#f0f0f0;
border-right:2px solid #fff;
color:#4e4e4e;
border-style: solid;
border-width: 1px;
border-color: gray;
}
.table-result td{
text-align:center;
height:40px;
font-size:12px;
line-height:22px;
color:#4e4e4e;
border-style: solid;
border-width: 1px;
border-color: gray;
padding-left: 2px;
padding-right:2px;
}
td
{
white-space:nowrap; }
</style>
</head>
<body style="width: 100%;overflow: scroll;"> <form action="upload!view.dhtml" method="post" style="margin-left:10px;">
<h2>原始记录</h2>
<textarea id="origrec" rows="5" cols="80">${logQueryDataModel.origrec }</textarea>
<h2>最新记录</h2>
<textarea id="lastrec" rows="5" cols="80">${logQueryDataModel.lastrec}</textarea>
</form>
</body>
</html>
<script>
$(document).ready(function(){ $("textarea").each(function(i){
var p = $(this).text();
if($.trim(p)=="") $(this).replaceWith("");
if(p!="\n\t\n\t"){
var json;
try{
json = JSON.parse(p);
var id="";
if($(this).attr("id")!= null)
id="id="+$(this).attr("id");
var t1="<table class=table-result "+id+" ><thead><tr>";
var flag=0;
var tr1="<tr>";
for(var j in json)
{
if(flag>0)
{
t1+="<tr>";
}
for(var item in json[j])
{
if(flag==0)
{
if(item!="")
t1+="<th class=center style='font-size:10px;height:15px;width:100%;'>"+item+"</th>";
tr1+="<td align=center style='height:15px;width:100%;'>"+json[j][item]+"</td>";
}else
{
t1+="<td align=center style='height:15px;width:100%;'>"+json[j][item]+"</td>";
}
}
if(flag==0)
t1+="</tr></thead>"+tr1+"</tr>";
else
t1+="</tr>";
flag++;
}
$(this).replaceWith(t1);
}catch(e)
{
}
}
});
var flag = 0;
$("textarea").each(function(i){
$(this).prev().remove();
$(this).remove();
flag+=1;
});
if(flag==2)
{
$("form").html("<h3>(此操作无详细数据)</h3>");
}
if(flag==1)
{
var ts = $("table[id$=rec]");
for(var i=0;i<ts.length;i+=2)
{
for(var c=0;c<ts[i].rows[1].cells.length;c++)
{
var a = ts[i].rows[1].cells[c].innerText;
var b = ts[i+1].rows[1].cells[c].innerText;
if(a!=b)
{
ts[i].rows[1].cells[c].style.backgroundColor='gray';
ts[i].rows[1].cells[c].style.color='white';
ts[i+1].rows[1].cells[c].style.backgroundColor='gray';
ts[i+1].rows[1].cells[c].style.color='white';
}else if(a==""&&b=="")
{
ts[i].rows[0].cells[c].style.display='none';
ts[i+1].rows[0].cells[c].style.display='none';
ts[i].rows[1].cells[c].style.display='none';
ts[i+1].rows[1].cells[c].style.display='none';
}
}
}
}
}); </script>
JSON数据转换成table表格的更多相关文章
- 【转】C#中将JSon数据转换成实体类,将实体类转换成Json
http://wo13145219.iteye.com/blog/2022667 http://json2csharp.chahuo.com/ using System; using System.C ...
- 利用JAVA反射机制将JSON数据转换成JAVA对象
net.sf.json.JSONObject为我们提供了toBean方法用来转换为JAVA对象, 功能更为强大, 这里借鉴采用JDK的反射机制, 作为简单的辅助工具使用, 有些数据类型需要进行转 ...
- 将JSON数据转换成JAVA的实体类
思路:首先将JSON格式的数据转换成JSONObject,然后将JSONObject转换成Java的实体类(其中类属性包括List等类型) Java实体类: SearchFilter 类 1 publ ...
- python - 将数据转换成 excl 表格, json 等文件 (dajngo - 打开网页后自动下载)
本篇只讲述怎么用. 具体 tablib 更多详细用法可参考博客 : https://blog.csdn.net/liangyuannao/article/details/41476277 # 不得不 ...
- 怎么把后台传过来的Json拼成table 用Jquery ajax()
页面上的表格定义:<table id="tableId"></table> js中的代码:var $parent0 = $('#tableId);//获取页 ...
- 把HDFS里的json数据转换成csv格式
1. 全景图 2. 用ListHDFS获取所有文件名 如果想重新再取一次,右健view state: 点击 clear state, 再运行,即可再次采集数据了. 3. 用FetchH ...
- 【转】参照protobuf,将json数据转换成二进制在网络中传输。
http://blog.csdn.net/gamesofsailing/article/details/38335753?utm_source=tuicool&utm_medium=refer ...
- C#实现调用接口数据获取数据格式化XML、json转成Table的方法
废话不多说,直接上代码: json 格式化转DataTable: result为从接口得到的数据,格式化json的方法主要来自Newtonsoft.Json JObject joUnit = JObj ...
- 把json数据转换成集合
Sting MessageList="";JSONArray json = JSONArray.fromObject(MessageList);JSONObject object ...
随机推荐
- SGU 208. Toral Tickets
208. Toral Tickets time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ou ...
- SaltStack的salt-ssh使用及LAMP状态设计部署(五)
一.salt-ssh的使用 官方文档:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html (1)安装salt-ssh [root@l ...
- 【C#】Unicode的流言终结者和编码大揭秘
如果你是一个生活在2003年的程序员,却不了解字符.字符集.编码和Unicode这些基础知识.那你可要小心了,要是被我抓到你,我会让你在潜水艇里剥六个月洋葱来惩罚你. 这个邪恶的恐吓是Joel Spo ...
- 洛谷P1404 平均数 [01分数规划,二分答案]
题目传送门 平均数 题目描述 给一个长度为n的数列,我们需要找出该数列的一个子串,使得子串平均数最大化,并且子串长度>=m. 输入输出格式 输入格式: N+1行, 第一行两个整数n和m 接下来n ...
- Python类总结-多态及鸭子类型
Python天生支持多态. 什么是多态: 一类事务的多种形态. 多态的一个例子 class Alipay(): def pay(self,money): print('用支付宝支付了%s元' % mo ...
- Python导入模块-Import
#1语法importimport module1,module2,module3,module4 #2from xx import xx 语句from module import name1,name ...
- Dijkstra【P2446】 [SDOI2010]大陆争霸
Background 在一个遥远的世界里有两个国家:位于大陆西端的杰森国和位于大陆东端的克里斯国.两个国家的人民分别信仰两个对立的神:杰森国信仰象征黑暗和毁灭的神曾·布拉泽,而克里斯国信仰象征光明和永 ...
- FastReport.Net使用:[11]公共对象属性介绍
公共对象属性介绍 1.Left(左),Top(上),Height(高度),Width(宽度) Left和Top,用来控制对象的位置:Height和Width用来控制对象的大小. 2.Anchor(基准 ...
- 我的OI生涯 第四章
第四章 晚上来机房的人越来越多了,我也注意到一个常年独自坐在一个角落的男人————郝哥. 郝哥为人很安静,只是那时我还不知道他好不好,就没有与他交流过什么,这个优秀的男人以后我们还会提到,这里先不讲. ...
- 91网漏洞打包#越权+爆破+存储xss可打cookie
漏洞一.主站存在登录口爆破 抓包,爆破一下 爆破成功 漏洞二.检测app时一处存储xss 在app登录后 我要提问那里插入xss 然后弹窗 可以打到cookie 漏洞三.app个人资料处平行越权可查看 ...