目前我在iPhone应用程序中工作,使用SBJson来解析来自webservice的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"}}
我试图解析这个,但值为null:
-(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
}
如何解析这个?请帮帮我
先谢谢
答案 0 :(得分: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 ..
答案 1 :(得分:1)
我希望this链接有助于完整的示例和解释。