0

我正在为 iOS 制作一个应用程序。该应用程序必须显示来自 MYSQL 数据库的结果,并且我在应用程序和数据库之间有一个 API。数据库发送有效的 JSON(这是在我的浏览器中):

[{"naam":"Maurice","id":2},{"naam":"Klaas","id":6},{"naam":"Mariska","id":8}]

但我在我的申请中看不到一个以上的结果。我搜索例如“M”,它只返回第一个莫里斯。我希望该应用程序也显示 Mariska。

谁能解释我如何在我的 iOS 应用程序中显示多个结果?

提前致谢,

莫里斯。

这里有更多代码:

 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:@"1" forKey:@"rw_app_id"];
    [request setPostValue:voornaam forKey:@"voornaam"];
    [request setPostValue:deviceUniqueIdentifier forKey:@"device_id"];
    [request setPostValue:@"1" forKey:@"test"];
    [request setDelegate:self];
    [request startAsynchronous];

    // Hide keyword
    [textField resignFirstResponder];

    // Clear text field
    textView.text = @"";

    // Start hud
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"Zoeken...";

    return TRUE;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    if (request.responseStatusCode == 400) {
        textView.text = @"Invalid code";        
    }
     else if (request.responseStatusCode == 403) {
        textView.text = @"Code already used";
    }
     else if (request.responseStatusCode == 204) {
        textView.text = @"No content";
    }
     else if (request.responseStatusCode == 412) {
        textView.text = @"Precondition Failed";
    }
     else if (request.responseStatusCode == 200) {
        NSString *responseString = [request responseString];
        NSDictionary *responseDict = [responseString JSONValue];
        NSString *naam = [responseDict objectForKey:@"naam"];

       // if ([unlockCode compare:@"com.razeware.test.unlock.cake"] == NSOrderedSame) {
            textView.text = [NSString stringWithFormat:@"Resultaten: %@", naam];
      //  } else {
           // textView.text = [NSString stringWithFormat:@"Resultaat: %@", unlockCode];
      //  }

    } 
    else {
        textView.text = @"Unexpected error API ERROR";
    }

}

- (void)requestFailed:(ASIHTTPRequest *)request
{    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    NSError *error = [request error];
    textView.text = error.localizedDescription;
}

@end

`

4

1 回答 1

0

尝试这个

 - (void)requestFinished:(ASIHTTPRequest *)request
 {    
     [MBProgressHUD hideHUDForView:self.view animated:YES];

      NSString *strResponse = [request responseString];
      SBJSON *objJSONParser = [[SBJSON alloc] init];
  NSDictionary *dictData = [objJSONParser objectWithString:strResponse error:nil];

      NSDictionary *dictResult = [dictData objectForKey: @"response"];
      NSLog(@"result Dict=%@",dictResult)      
      NSArray *arrTemp=(NSArray *)[dictData objectForKey:@"response"];
        NSLog(@"Array=%@",arrTemp)   

     //print both one by one is it work or not?
于 2013-05-15T10:14:43.153 回答