0

目前我在 iPhone 应用程序中工作,使用 SBJson 来解析来自 web 服务的 Json 响应,但我没有解析它。

这里我提到了 SBJson 文件供您参考:

 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"}}

我试图解析这个,但值是空的:

-(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
}

如何解析这个?请帮我

提前致谢

4

1 回答 1

1

保证您的应用程序在未来版本中使用 Apple 的库/类(只是一个建议)。如果您使用NSJSONSerialization解决方案将如下所示..

// 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 ..
于 2012-09-26T14:16:47.107 回答