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];
效果图:
南来地,北往的,上班的,下岗的,走过路过不要错过!
======================个性签名=====================
之前认为Apple 的iOS 设计的要比 Android 稳定,我错了吗?
下载的许多客户端程序/游戏程序,经常会Crash,是程序写的不好(内存泄漏?刚启动也会吗?)还是iOS本身的不稳定!!!
如果在Android手机中可以简单联接到ddms,就可以查看系统log,很容易看到程序为什么出错,在iPhone中如何得知呢?试试Organizer吧,分析一下Device logs,也许有用.