-2

我从 Ios 开发开始,在操作 Json 创建的数组时遇到了一些麻烦:我在我的应用程序中调用了一个返回数据的 Web 服务:

{evenements =(
             ({
            dateEvenement ={
                1 = "01-01-2013";
                2 = "02-01-2013";
                3 = "03-01-2013";
                4 = "04-01-2013";
            };
            idEvenement = 61;
            nbrInvite = 1;
            nomEvenement = "My event Name";
            nomUtilisateur = "Lucas ";
        }
    ),
 );
}

除了 "dateEvenement" 之外,我可以通过以下代码获取所有值:

NSArray *msgList;
msgList = [ jsonResults objectForKey:@"evenements" ];

for (NSDictionary *evenements in msgList) {

    for (NSDictionary *evenement in evenements ) {

        NSString *idEvenement = [evenement objectForKey:@"idEvenement"];
        NSString *nomUtilisateur = [evenement objectForKey:@"nomUtilisateur"];
        NSString *nomEvenement = [evenement objectForKey:@"nomEvenement"];
        NSString *nbrInvite = [evenement objectForKey:@"nbrInvite"];

        NSArray *dates = [ evenement objectForKey:@"dateEvenement" ];
     }
}

你能帮我获取“dateEvenement”的数据吗

4

1 回答 1

1

那么在你的 JSON 中,dateEvenement不是一个数组而是一个字典:

NSDictionary *dates = [ evenement objectForKey:@"dateEvenement"];

for(NSNumber *key in dates) {
   NSString *dateString = [dates objectForKey:key];
   NSLog(%@ : %@, key, dateString); 
}

正如您在 JSON 示例中声明的那样,字典的键是数字,因此您应该NSNumber反对键类型。

于 2013-01-18T08:56:44.310 回答