我正在尝试使用Json响应来填充tableview这是我从回调中读取的Json
user.plan_dates
这是我的代码,但它打破了应用程序的任何想法,我如何更改我的代码,以使其填充tableview与其对应的部分和每个部分中的行
user.plan_dates.where(attribute: test)
这是我的两个对象分支.m部分
{
"Categories": {
"Beer": [
{
"id": "3",
"nombre": "Bud ligth",
"precio": "10",
"categoriaid": "3",
"url": "false"
}
],
"Whiskey": [
{
"id": "2",
"nombre": "Red label",
"precio": "100",
"categoriaid": "2",
"url": "false"
}
]
}
}
答案 0 :(得分:2)
你正在以错误的方式解析json响应, 试试这个,
SELECT
e.EmpName,
d.DepartmentName,
l.EnrollNumber,
v.VerifyModeName,
CAST(PunchTime as DATE)Check_Date,MIN(CAST(PunchTime as Time))[TimeIN], MAX(Cast(PunchTime as Time))[TimeOUT],
RIGHT('0' + CAST(DATEDIFF(SECOND, MIN(CAST(PunchTime as Time)), MAX(Cast(PunchTime as Time))) / 3600 AS VARCHAR),2) + ':' +
RIGHT('0' + CAST((DATEDIFF(SECOND, MIN(CAST(PunchTime as Time)), MAX(Cast(PunchTime as Time))) / 60) % 60 AS VARCHAR),2) + ':' +
RIGHT('0' + CAST(DATEDIFF(SECOND, MIN(CAST(PunchTime as Time)), MAX(Cast(PunchTime as Time))) % 60 AS VARCHAR),2) as Duration
FROM Department d
INNER JOIN Employee e
ON e.DeptID = d.Id
LEFT JOIN AttLog l
ON e.EnrollNumber = l.EnrollNumber
LEFT JOIN VerifyModes v
ON l.VerifyMode = v.VerifyModeId
WHERE cast(l.PunchTime as Date) between '2015-07-22' and '2015-07-22'
GROUP BY
e.EmpName, d.DepartmentName, l.EnrollNumber, v.VerifyModeName, CAST(PunchTime as DATE)
ORDER BY Check_Date
使用NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.menuInfo options:NSJSONReadingMutableContainers error:nil];
NSDictionary *cat = [json objectForKey:@"Categories"];
NSMutableArray *categoryArray = [NSMutableArray new];
for(NSString *key in [cat allKeys]){
Categorias *category = [[Categorias alloc]initWithNombre:key];
NSArray *listTagDict = [cat objectForKey:key];
for (NSDictionary *prod in listTagDict) {
NSString* pID = [prod objectForKey:@"id"];
NSString* pNombre = [prod objectForKey:@"nombre"];
NSString* pPrecio = [prod objectForKey:@"precio"];
NSString* pUrl = [prod objectForKey:@"url"];
Productos* productos = [[Productos alloc]initWithNombre:pNombre productoID:pID precio:pPrecio iconUrl:pUrl];
[category addRow:productos];
}
[categoryArray addObject:category];
}
填充tableview。
在此,categoryArray
计数将是节数,每个节包含每个类别categoryArray
数组的行。
rowData