尝试从数组中检索值时遇到问题。我想从这个数组中获取所有值,以便在 IUTableView 中显示它们。
我应该使用双精度函数吗?
{
1 = {
dishId = 1;
dishName = "Tomato Salades";
dishPrice = 13;
dishTypeId = 1;
dishTypeName = Starter;
};
2 = {
dishId = 2;
dishName = "Leeks Salades";
dishPrice = 12;
dishTypeId = 1;
dishTypeName = Starter;
};
3 = {
dishId = 3;
dishName = Fries;
dishPrice = 14;
dishTypeId = 2;
dishTypeName = "Main Course";
};
4 = {
dishId = 4;
dishName = Beef;
dishPrice = 15;
dishTypeId = 2;
dishTypeName = "Main Course";
};
7 = {
dishId = 7;
dishName = "Cheese Cake";
dishPrice = 8;
dishTypeId = 3;
dishTypeName = Dessert;
};
menuCountry = France;
menuDescription = "un menu pas comme les autres pour une region pas comme les autres";
menuId = 1;
menuName = "Autour de l\\Alsace";
menuState = 1;
}
这是我的 Python 代码,它在 Array 中创建一个 Dictionary :
def getDishOfTheWeek():
menuArray = []
menuDic = Ddict(dict)
for menu in Menus.select().where(state=True):
menuDic['menuId']=menu.id
menuDic['menuName']=menu.name
menuDic['menuCountry']=menu.country.name
menuDic['menuDescription']=menu.description
menuDic['menuState']=menu.state
for d in DishMenuRels.select().where(menu = menu.id).join(Dishes).join(DishTypes).order_by((DishTypes,'name')):
menuDic[str(d.dish.id)] = {}
menuDic[str(d.dish.id)]['dishTypeName'] = d.dish.dishType.name
menuDic[str(d.dish.id)]['dishTypeId'] = d.dish.dishType.id
menuDic[str(d.dish.id)]['dishId'] = d.dish.id
menuDic[str(d.dish.id)]['dishName'] = d.dish.name
menuDic[str(d.dish.id)]['dishPrice'] = d.dish.price
menuArray.append(menuDic)
return json.dumps(menuArray)
这是我的 Objectiv-C 代码,用于获取 DataJson 并将其放入数组中:
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
switch (streamEvent) {
case NSStreamEventOpenCompleted:
[[ConnectionSingleton getInstance] setConnectionMade:YES];
NSLog(@"Stream opened");
break;
case NSStreamEventHasBytesAvailable:
if (theStream == inputStream) {
uint8_t buffer[1024];
int len;
while ([inputStream hasBytesAvailable]) {
len = [inputStream read:buffer maxLength:sizeof(buffer)];
if (len > 0) {
NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
output = [output substringToIndex:[output length] - 2];
if (nil != output) {
NSError* error; // Obligatoir pour le JSON
menu = [NSJSONSerialization JSONObjectWithData:[output dataUsingEncoding:NSUTF8StringEncoding] options:
NSJSONReadingMutableContainers error:&error]; // Put Json in the Array
[[self tableView] reloadData]; // Reload Array to populate it
}
}
}
}
break;
case NSStreamEventErrorOccurred:
NSLog(@"Can not connect to the host!");
break;
case NSStreamEventEndEncountered:
break;
default:
NSLog(@"Unknown event");
}
}