我想处理来自json的int值,即0。 这是我的代码,但它无法运行,我的应用程序在运行时崩溃。
UILabel *like=(UILabel *)[cell viewWithTag:3];
if ([[json objectAtIndex:indexPath.row ]objectForKey:@"likes"] == (id)[NSNull null]) {
like.text=@"-";
}
else{
like.text=[[json objectAtIndex:indexPath.row]objectForKey:@"feed_text"];
}
这是我的回复
{
"feed_id": "2",
"group_id": "1",
"group_name": "Church",
"feed_text": "Hi+this+is+my+first+Post+in+Church+group",
"likes": 0,
"comments": 0,
"latitude": "21.180407400000000000",
"longitude": "66308dbc30ae53223f1213f793700381"
}
任何人都知道如何处理零值? 谢谢
答案 0 :(得分:1)
这是我用来处理json中的0值的最终代码...
1000.times do
puts "Press Enter"
gets
x = rand (0..5)
y = rand (0..5)
# "x" counter
10.times do |xx|
meter = rand (0..5)
if xx < 9
print meter
print "\r"
sleep 0.08
else print x
end
end
puts
# "y" counter
10.times do |yy|
meter = rand (0..5)
if yy < 9
print meter
print "\r"
sleep 0.08
else print y
end
end
puts
end
你只需传递你的参数和在UILabel上设置标签,例如我已经设置了11并且它的工作就像一个魅力。 我希望它会有用。
谢谢
答案 1 :(得分:0)
if ([[[json objectAtIndex:indexPath.row ]objectForKey:@"likes"] intValue]==0) {
like.text=@"-";
}
else{
like.text=[[json objectAtIndex:indexPath.row]objectForKey:@"feed_text"];
}
答案 2 :(得分:0)
global variable Bool flag;
flag=true;
- (IBAction)buttonHandlerTreatmentPointImageChange:(BLButton *)sender {
__block CATransform3D transform;
if (flag)
{
flag=false;
transform = CATransform3DMakeRotation(-M_PI / 1.1, 0.0, 1.0, 0.0);
}
else
{
flag=true;
transform = CATransform3DMakeRotation(0.0, 0.0, 1.0, 0.0);
}
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
transform.m34 = 1.0f / 2500.0f;
self.viewToFlip.layer.transform = transform;
}
completion:^(BOOL finished)
{
}];
}