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 ...
随机推荐
- JAVA 抽象类、接口
一.抽象类 1.语法定义 在类前面使用 abstract 修饰的类就是抽象类 2.应用场景: (1)在某些情况下,某个父类只是知道其子类应该包含怎样的方法,但无法准确知道这些子类如何实现这些方法. ( ...
- 《HBase权威指南》学习笔记
第一章 简介 背景: GFS:集群存储海量数据,数据在节点间冗余复制,即使一台存储服务器发生故障,也不会影响可用性. GFS的缺点:适合存储少许非常大的文件,而不适合存储大量小文件,因为文件的元数据 ...
- GO基本数据结构练习:数组,切片,映射
按<GO IN ACTION>的书上进行. 应该是第二次了哦~~ package main import ( "fmt" ) func main() { array : ...
- mysql建立自增主键的插入,及自动插入当前时间
MYSQL里用这两个字段,几乎都是必须的. 以前都是自动建立的,现在手把手建立的时候,就要找资料来搞定了. 参考URL: http://blog.csdn.net/Weicleer/article/d ...
- MySQL的表管理
首先,先选择数据库(极其特别重要,如果不选择,将默认为第一个数据库) mysql > use db_name; 查看所有表 mysql > show tables; 1.创建表 creat ...
- 字典dict常用方法
字典是列表中常用的方法,我们经常处理字典,字典嵌套,很多复杂的操作都来自于基础,只是改变了样式而已,本质是不变的.下面来看看字典中常用的功能都有那些: 1.clear(self) def cl ...
- 易普优APS高级计划排程系统系列提纲:行业知识,业务建模,排程算法,计划可视化,平台框架,案例分享
专注于高级计划排程系统研发与实施10来年了,国内外各种APS软件基本都研究过,这里列个提纲主要从6个方面跟大家一起讨论分享,欢迎大家鼓掌或拍砖 易普优APS高级计划排程系统系列001:行业知识,APS ...
- SpringBoot入门系列
集合redis,mysql,测试例子 http://blog.csdn.net/lxhjh/article/details/51764604
- React Native踩坑之Unable to load script from assets
报错: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged corr ...
- HDU 6052 To my boyfriend(概率 贡献)
To my boyfriend Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...