我在将数据插入tableView中的单元格时遇到问题。当我搜索错误源时,我看到我的webservice正在返回null值。因此,当我将名称调用到单元格时,它会使参数化为空。因此,原因是数据库问题,我只想跳过添加例如:{“name”:“null”}
在其他服务中,我得到空值为空...所以它不会导致问题..我认为它是一个字符串的空值。
以下是一个例子:
{
"24_7" = 0;
address = "avenue innsbruck";
city = GRENOBLE;
country = FR;
dst = "14007.2046741012";
"h_saturday" = " - ";
"h_sunday" = " - ";
"h_week" = " - ";
id = 324;
"location_lat" = "45.154";
"location_long" = "5.73387";
name = "<null>";
"tel_1" = 0476544254;
"tel_2" = "";
zipcode = 38000;
}
我只想在这里解析json时跳过添加这个。
NSString *theJSON = [request responseString];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *jsonDictionary = [parser objectWithString:theJSON error:nil];
//NSLog(@"OkRequest || %@ ", jsonDictionary);
[_jsonStation removeAllObjects];
for (NSDictionary *taxi in jsonDictionary)
{
[_jsonStation addObject:taxi];
}
答案 0 :(得分:12)
您可以在循环中测试对象是否为null:
if ([taxi isKindOfClass:[NSNull class]])
continue;
//else, process it