XSLT存档  

不及格的程序员-八神

 查看分类:  ASP.NET XML/XSLT JavaScripT   我的MSN空间Blog
posts - 173,  comments - 1172,  trackbacks - 0
公告

json:

1 [{"iTagID":9,"cTag":"Liuxx测试-标签-1","cUnit":"TT","values":[{"serial_number":1,"cDate":"2012-11-05","fValue":30},{"serial_number":2,"cDate":"2013-01-10","fValue":400},{"serial_number":3,"cDate":"2013-01-13","fValue":200},{"serial_number":4,"cDate":"2013-01-16","fValue":200},{"serial_number":5,"cDate":"2013-01-16","fValue":290},{"serial_number":6,"cDate":"2013-01-16","fValue":350},{"serial_number":7,"cDate":"2013-01-16","fValue":310},{"serial_number":8,"cDate":"2013-01-17","fValue":200},{"serial_number":9,"cDate":"2013-01-17","fValue":15},{"serial_number":10,"cDate":"2013-01-17","fValue":20},{"serial_number":11,"cDate":"2013-05-17","fValue":30}]},{"iTagID":10,"cTag":"Liuxx测试-标签-2","cUnit":"VAR","values":[{"serial_number":1,"cDate":"2012-11-05","fValue":60},{"serial_number":2,"cDate":"2013-01-10","fValue":100},{"serial_number":3,"cDate":"2013-01-13","fValue":50},{"serial_number":4,"cDate":"2013-01-16","fValue":100},{"serial_number":5,"cDate":"2013-01-16","fValue":109},{"serial_number":6,"cDate":"2013-01-16","fValue":200},{"serial_number":7,"cDate":"2013-01-16","fValue":300},{"serial_number":8,"cDate":"2013-01-17","fValue":50},{"serial_number":9,"cDate":"2013-01-17","fValue":16},{"serial_number":10,"cDate":"2013-01-17","fValue":30},{"serial_number":11,"cDate":"2013-05-17","fValue":60}]},{"iTagID":11,"cTag":"Liuxx测试-标签-3","cUnit":"VARh","values":[{"serial_number":1,"cDate":"2013-01-16","fValue":1630}]},{"iTagID":12,"cTag":"Liuxx测试-标签-4","cUnit":"W","values":[{"serial_number":1,"cDate":"2013-01-09","fValue":3},{"serial_number":2,"cDate":"2013-01-13","fValue":5},{"serial_number":3,"cDate":"2013-01-14","fValue":6},{"serial_number":4,"cDate":"2013-01-16","fValue":9}]}]
 1 NSMutableArray *tempSection = [NSMutableArray arrayWithCapacity:10];
 2              
 3              NSMutableArray *headArray = nil;
 4              for (id ele in json)
 5              {
 6                  NSDictionary *dict = @{
 7                  @"tag" : [NSString stringWithFormat:@"%@", [ele objectForKey:@"cTag"]],
 8                  @"unit": [NSString stringWithFormat:@"%@", [ele objectForKey:@"cUnit"]]
 9                  };
10                  if(headArray == nil)
11                  {
12                      headArray = [NSMutableArray arrayWithObject:dict];
13                  }
14                  else
15                  {                     
16                      [headArray addObject:dict];
17                  }
18              }
19              int iColumnCount =0;
20              for(int i=0; i<[json count]; i++)
21              {
22                  iColumnCount = MAX(iColumnCount, [[json[i] objectForKey:@"values"] count]);
23                  for(int j=0;j<iColumnCount;j++)
24                  {
25                      if([tempSection count] == j) //在数据行数组中再加一行
26                      {
27                          NSMutableArray *rowArray = [NSMutableArray arrayWithCapacity:10];
28                          [tempSection addObject:rowArray];
29                      }
30                      if(j >= [[json[i] objectForKey:@"values"] count]) //放空占位符
31                      {
32                          [tempSection[j] addObject:[NSNull null]];
33                          continue;
34                      }
35                      id colValue1 = [[json[i] objectForKey:@"values"][j] objectForKey:@"serial_number"];
36                      id colValue2 = [[json[i] objectForKey:@"values"][j] objectForKey:@"cDate"] == nil ? @"" : [[json[i] objectForKey:@"values"][j] objectForKey:@"cDate"] ;
37                      id colValue3 = [[json[i] objectForKey:@"values"][j] objectForKey:@"fValue"];                    
38                                          
39                      [tempSection[j] addObject:@{@"serial_number":colValue1, @"date":colValue2, @"value":colValue3}];
40                  }
41              }
42 
43              [tempSection insertObject:headArray atIndex:0];

效果图:

posted on 2013-01-25 16:35 不及格的程序员-八神 阅读(...) 评论(...) 编辑 收藏