2012-09-26 4 views
0

Actuellement, je travaille dans l'application iPhone, en utilisant SBJson, pour analyser la réponse de Json à partir de webservice mais je ne l'ai pas analysé.Comment analyser le fichier JSON dans l'iPhone?

Ici je l'ai mentionné fichier SBJson pour votre référence:

Array 
    (
     [0] => 21 
     [s.no] => 21 
     [1] => Table243322 
     [table_id] => Table424242 
     [2] => arun123 
     [username] => aru22n123 
     [3] => sam101 
     [friend_user_name] => sa323m101 
     [4] => 0 
     [game_status] => 0 
    ) 
    {"status":"1","error":{"0":"Table1684242538","table_id":"Table168424538","1":"KH,AC,10S,8D,2C,4H,JH,3S,10C,7D,3C,4D,7S","play_cards1":"KH,AC,10S,8D,2C,4H,JH,3S,10C,7D,3C,4D,7S","2":"QH,8H,2D,AS,KC,3D,6D,QD,9D,3H,2H,JD,AH","play_cards2":"QH,8H,2D,AS,KC,3D,6D,QD,9D,3H,2H,JD,AH","3":"10H","joker_card":"10H","4":"7C","open_deck":"7C","5":"AD,4C,9S,6S,QC,5C,8C,2S,4S,KS,5D,JS,RJ2,6H,JC,6C,9H,KD,10D,7H,QS,9C,5S,5H,RJ1,8S","closed_decks":"AD,4C,9S,6S,QC,5C,8C,2S,4S,KS,5D,JS,RJ2,6H,JC,6C,9H,KD,10D,7H,QS,9C,5S,5H,RJ1,8S"}} 

J'ai essayé d'analyser, mais la valeur vient nulle:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSString *jsonStr1 = [[NSString alloc] initWithData:mutaebleData encoding:NSUTF8StringEncoding]; 
    NSLog(@"jsonStr1 : %@", jsonStr1); 

    SBJSON *Json = [[SBJSON alloc]init]; 
    NSDictionary *dic= (NSDictionary *) [Json objectWithString:jsonStr1 error:nil]; 

     // dic = null, dic value comes always null 
} 

Comment analyser ce? S'il vous plaît aidez-moi

Merci à l'avance

Répondre

1

pour garantir votre application pour les futures versions utilisent la bibliothèque d'Apple/classes (juste une suggestion). Si vous utilisez NSJSONSerialization la solution sera comme ci-dessous ..

// 1) data is an ivar of NSData 
// 2) i used delegate methods of NSURLConnection to fetch data from server 
    NSError *error=nil; 
    id result=[NSJSONSerialization JSONObjectWithData:data options: 
      NSJSONReadingMutableContainers error:&error]; 
// use result as how you want. you can use NSDictionary too instead of id .. 
+0

Merci pour votre réponse – SampathKumar

+0

Si la réponse a été utile s'il vous plaît pouvez-vous l'accepter? – ilhnctn

+0

Merci pour votre aide – SampathKumar

1

J'espère lien this aidera l'exemple avec des explications.