-4

Web サービスからデータを取得しています。データを に入れています。メソッドNSDictionaryを使用してvalueForKeyデータを配列にバインドしています。17 個の要素がありますが、最初のデータに二重引用符があるため、カウントは 1 として表示されます。サンプルコードは次のとおりです。

- (void)BarChartfetchedData:(NSData *)responseData   {

    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    BarChartDictionary = [json   objectForKey:@"Report_DashboardDetailProfitBranchResult"];
    NSArray * new = [[NSArray alloc]initWithObjects:[BarChartDictionary valueForKey:@"ProfitAmount"],nil];

    NSLog(@"mypieclass.itemArray: %@ ",new);
    NSLog(@"Total: %lu ",(unsigned long)[new count]);
    NSLog(@"BarChartDictionary: %lu ",(unsigned long)[BarChartDictionary count]);
}

合計数17を取得する必要があります。その方法、提案は役に立ちます。

4

2 に答える 2

2

試す

NSArray * new = [[NSArray alloc]initWithArray:[BarChartDictionary valueForKey:@"ProfitAmount"]]; // if not using ARC you will have to release it.

あるいは単に

NSArray *new = BarChartDictionary[@"ProfitAmount"];

セサミストリートハンドパペットの説明:

(  // <- begin top level array
    ( // <- begin first element in top level array. it is another array, a nested array
        "16291443.69", // <- first element in the nested array
         6621797,      // <- second element in the nested array
         5692671, 
         2477348, 
         2362607, 
         2281261, 
         886410, 
         848799, 
         762441, 
         706688, 
         497076, 
         492402, 
         188320, 
         124595, 
         96625, 
         62905, 
         60200       // <- last element in the nested array
    ) // <- end first element in top level array
) // <- end top level array

--> 最上位の配列には on 要素があります。これは、17 個の要素を持つ別の配列です。

于 2013-07-15T13:46:02.157 に答える
0

Is the dictionary object being printed correctly with the 17 value in it? If the dictionary itself is correct, you may need to parse the count object in the dictionary differently.

It may be the case that you are printing count with a wrong format, as it will not be really be a long unsigned...since you cast it to long unsigned, the compiler will not display a warning...

于 2013-07-15T13:34:25.320 に答える