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 ...
随机推荐
- C++大数据处理
转:http://blog.csdn.net/v_july_v/article/details/7382693 作者:July出处:结构之法算法之道blog 前言 一般而言,标题含有“秒杀”,“99% ...
- JS中firstChild,lastChild,nodeValue属性
childNodes 在JavaScript中,使用childNodes属性可以返回一个数组,这个数组包含给定元素节点的全体子节点. firstChild firstChild 这句代码等价于 目标元 ...
- 【企业通讯录app番外篇】怎么样创建服务端?
本文将指导大家如何去创建企业通讯录app的服务端 除了获取图片,客户端与服务端唯一的交互就是获取最新数据,如果该用户不能获取数据(用户名密码错误.用户离职被删)则返回空. 1:典型的交互流程如下: 用 ...
- CentOS7.5 firefox Flash插件更新
CentOS7自带的firefox没有flash插件,所以是没有办法在网页上看视频的,需要自己手动安装 1.下载 打开flash官网https://get.adobe.com/flashplayer/ ...
- Http 请求 GET和POST的区别
GET和POST还有一个重大区别,简单的说: GET产生一个TCP数据包;POST产生两个TCP数据包. 长的说: 对于GET方式的请求,浏览器会把http header和data一并发送出去,服务器 ...
- 转:xxe attack学习
小结 1.http包发送类型:content-type:text/xml2.xxe漏洞非常危险, 因为此漏洞会造成服务器上敏感数据的泄露,和潜在的服务器拒绝服务攻击.要去校验DTD(document ...
- Python学习之pillow库入门
http://python.jobbole.com/84956/ 我还是搬运工......
- Java常用工具类之IO流工具类
package com.wazn.learn.util; import java.io.Closeable; import java.io.IOException; /** * IO流工具类 * * ...
- Xml配置文件属性的说明
Xml配置文件属性的说明: <bean id="TheAction" ⑴ class="net.xiaxin.spring.qs.UpperAction" ...
- hdu dp 1257 最小拦截系统
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...