如何获取"status"响应并传递它以隐藏按钮免受以下 json 响应?



我想根据我的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 中获取"状态"值,并在状态 = 2 或 3 时隐藏按钮,否则保持可见(当状态 = 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!)
         }
    }
}

试试下面的代码。

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 :)

最新更新