0

JSON 文字列を取得しようとしていますが、一部の単語に「á、é、ç」などが含まれています。

JSON は次のとおりです。

{"Error":"", "Result":{"Transacoes": [{"ClienteID":"1","ID":"915","Banco":"Bradesco","Fornecedor":"","Tipo":"Cartão de crédito - Bradesco Visa","ValorCredito":"0,0000","ValorDebito":"4000,0000","Vencimento":"","Pagamento":"03/08/2012 00:00:00","Descricao":"Cartão Bradesco Visa","Lançamento":"03/08/2012 15:18:12"},{"ClienteID":"1","ID":"916","Banco":"Bradesco","Fornecedor":"","Tipo":"Alinhamento da Conta Bancária","ValorCredito":"22398,9200","ValorDebito":"0,0000","Vencimento":"","Pagamento":"02/08/2012 00:00:00","Descricao":"FGTS","Lançamento":"07/08/2012 11:12:16"}]}}

コードは次のとおりです。

-(void)viewWillAppear:(BOOL)animated {
NSString *urlAddress = [NSString stringWithFormat:@"http://SITE?action=transacoes&AuthToken=%@&DataDe=02/08/2012&DataAte=03/08/2012", self.usuario.authToken];

NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest: request
                                        success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@", JSON);
                                        }
                                        failure: ^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON){
                                            NSLog(@"ERROR: %@", error);
                                        }];

[operation start];
}
4

1 に答える 1

0

Exception要求しているサーバーからデータを取得できないため、アプリがスローします。SO 最初にデータを受信することを確認してから、次のコードを実装します

次のコードを試してjsonデータを解析してください。アプリで試してみましたが、その特別なシンボルでも問題なく動作しています。

NSString *urlAddress = [NSString stringWithFormat:@"http://SITE?action=transacoes&AuthToken=%@&DataDe=02/08/2012&DataAte=03/08/2012", self.usuario.authToken];

NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSHTTPURLResponse* urlResponse = nil;

NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

if([responseData bytes] > 0)
{
    // It will work only IOS 5.0 or later version otherwise you can use any third party JSON parsers (eg. SBJSON)
    NSDictionary* json = [NSJSONSerialization
                          JSONObjectWithData:responseData
                          options:NSJSONReadingMutableLeaves
                          error:&error];
    NSLog(@"%@",[[[[json objectForKey:@"Result"] objectForKey:@"Transacoes"] objectAtIndex:1] valueForKey:@"Descricao"]);
    NSLog(@"%@",[[[[json objectForKey:@"Result"] objectForKey:@"Transacoes"] objectAtIndex:1] valueForKey:@"Tipo"]);
}
于 2013-04-23T11:16:14.500 に答える