我想根据我的json回复"状态"隐藏一个uibutton。请详细说明我(我是初学者)。 以下是从xcode控制台获取的json响应。
JSON: {
customerstatus = {
1 = {
bookingid = 469;
status = 1;
};
};
以下是获取上述回复的代码。
-(void)SendtoGetMaterialStatus
{
PMDReachabilityWrapper *reachability = [PMDReachabilityWrapper sharedInstance];
if ([reachability isNetworkAvailable])
{ NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSDictionary *savedValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"service"];
NSLog(@"Checkingfast%@", savedValue);
NSDictionary *temp = @{
@"ent_sess_token":flStrForStr([ud objectForKey:iServeCheckUserSessionToken]),
@"ent_dev_id":flStrForStr([Utilities getDeviceId]),
@"customerid":savedValue
//send the customer id from userdefault
};
NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:temp];
NSLog(@"Checking User Default Customer ID%@",temp);
[[WebServiceHandler sharedInstance] sendRequestTypeGetReportMaterialStatus:params andDelegate:self];
NSLog(@"Customer ID sent to Recieve the Material Status%@", params);
}
else
{
[[ProgressIndicator sharedInstance]hideProgressIndicator];
[UIHelper showMessage:iServeNetworkErrormessage withTitle:LS(@"oops!")delegate:self];
NSLog(@"customer ID didn't send!.");
}
// [self makePostRequest:RequestTypeGetReportMaterialStatus path:kRequestTypeGetReportMaterialStatus params:params delegate:delegate];
}
我想采取"状态"来自JSON的值,当status = 2或3时隐藏按钮,否则保持可见(当status = 1时)。
我按照以下方法传递回复。请根据我的代码给我代码片段。感谢。
-(void)didFinishLoadingRequest:(RequestType)requestType withResponse:(id)response error:(NSError *)error
{
switch (errFlag) {
case 1:
{
[[ProgressIndicator sharedInstance]hideProgressIndicator];
if (errNum == 7 || errNum == 6 || errNum == 78 || errNum == 83)//Session Expired
{
[[Logout sharedInstance] deleteUserSavedData:response[@"errMsg"]];
}
else
{
[UIHelper showMessage:response[@"errMsg"] withTitle:LS(@"Message")delegate:self];
}
}
break;
case 0:
{
if(requestType == RequestTypeGetReportMaterialStatus)
{
// Passing response and hiding the button
// ...........(help me!)
}
}
}
答案 0 :(得分:0)
尝试以下代码。
NSArray* customerstatus = response[@"customerstatus"][@"1"];
NSInteger fisrtStatus = [customerstatus[0][@"status"] integerValue];
NSInteger secondStatus = [customerstatus[1][@"status"] integerValue];
if (fisrtStatus == 1) {
// Show your buttons
} else {
// Hide your buttons
}
// Do what you want with secondStatus :)