JSON 数据处理问题


 [manager POST:@"myurl here" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"Response %@", responseObject);

if ([responseObject[@"code"]isEqualToString: @"202"] )
            {
               totalorders = responseObject[@"orders"];
                for (int i= 0 ; i< [totalorders count]; i++)
                {
                    dataDictionary =[[totalorders objectAtIndex:i]objectForKey:@"odate"];

                    [dates addObject:[dataDictionary objectForKey:@"odate"]];
                    NSLog(@"%@",dataDictionary );

                }

            }


我也试过这个

dates addobject: [dataDictionary allValues];

就是我记录的日期,现在在这里我无法将数据从datadictionary存储到NSarray需要帮助。
谢谢我稍后必须在表格视图中显示数据。
请为我提供一些 JSON 解析基础知识的链接

<br><br> My Output is 2015-01-15 16:56:54.851 Test Application [4245:474718] 2015-01-12
2015-01-15 16:56:54.851 Test Application[4245:474718] 2015-01-08
2015-01-15 16:56:54.852 Test Application[4245:474718] 2015-01-08
2015-01-15 16:56:54.852 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.852 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.853 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.853 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.854 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.855 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.855 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.855 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.856 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.858 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.858 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.859 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.859 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.859 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.860 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.860 Test Application[4245:474718] 2015-01-05
2015-01-15 16:56:54.861 Test Application[4245:474718] 2015-01-02
2015-01-15 16:56:54.861 Test Application[4245:474718] 2014-11-25
2015-01-15 16:56:54.861 Test Application[4245:474718] 2014-11-25
2015-01-15 16:56:54.862 Test Application[4245:474718] 2014-11-25
2015-01-15 16:56:54.862 Test Application[4245:474718] 2014-11-25
2015-01-15 16:56:54.863 Test Application[4245:474718] 2014-11-17
2015-01-15 16:56:54.863 Test Application[4245:474718] 2014-11-17
2015-01-15 16:56:54.866 Test Application[4245:474718] 2014-11-17
2015-01-15 16:56:54.867 Test Application[4245:474718] 2014-11-13
2015-01-15 16:56:54.867 Test Application[4245:474718] 2014-11-13
2015-01-15 16:56:54.868 Test Application[4245:474718] 2014-11-13
2015-01-15 16:56:54.868 Test Application[4245:474718] 2014-11-13
2015-01-15 16:56:54.868 Test Application[4245:474718] 2014-11-13
2015-01-15 16:56:54.869 Test Application[4245:474718] 2014-11-13
2015-01-15 16:56:54.869 Test Application[4245:474718] 2014-11-12
2015-01-15 16:56:54.870 Test Application[4245:474718] 2014-11-12
2015-01-15 16:56:54.870 Test Application[4245:474718] 2014-11-10
2015-01-15 16:56:54.871 Test Application[4245:474718] 2014-11-10
2015-01-15 16:56:54.871 Test Application[4245:474718] 2014-11-10
2015-01-15 16:56:54.871 Test Application[4245:474718] 2014-11-10
2015-01-15 16:56:54.872 Test Application[4245:474718] 2014-11-06
2015-01-15 16:56:54.872 Test Application[4245:474718] 2014-11-05
2015-01-15 16:56:54.874 Test Application[4245:474718] 2014-11-05
2015-01-15 16:56:54.874 Test Application[4245:474718] 2014-11-05
2015-01-15 16:56:54.875 Test Application[4245:474718] 2014-11-05

您已经使用以下代码行正确向下钻取到日期对象

[[totalorders objectAtIndex:i]objectForKey:@"odate"]

所以没有必要再次获取同一键的对象

此外,当您尝试将 nil 对象添加到数组时,您可能会崩溃 但惊讶地发现事实并非如此,因此您可能没有分配"日期"数组

下面是已修复问题的代码

dates=[NSMutableArray new];
if ([responseObject[@"code"]isEqualToString: @"202"] )
            {
               totalorders = responseObject[@"orders"];
                for (int i= 0 ; i< [totalorders count]; i++)
                {
                    dataDictionary =[[totalorders objectAtIndex:i]objectForKey:@"odate"];

                    [dates addObject:dataDictionary];
                    NSLog(@"dates %@",dates );

                }

            }

请注意,发送到 nil 对象的消息不会导致崩溃,但添加 nil 对象可以

最新更新