2013-07-15 75 views
-4

我從Web服務獲取數據,我將它放到NSDictionary,並且使用valueForKey方法,我將數據綁定到一個數組中,它有17個元素,但計數顯示爲1,因爲第一個數據有雙引號。這裏的示例代碼:Nsdictionary錯誤地顯示數據

- (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.如何做到這一點,任何建議將是有益的。

+0

您應該向我們顯示數據。 – vikingosegundo

+1

這個問題錯過了重要的信息。它是關於解析,但是不需要顯示需要解析的數據。 – vikingosegundo

+0

我添加了nslog圖像,但沒有10個聲望我無法添加圖像。 –

回答

2

嘗試

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

或只是

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

芝麻街布袋木偶explan ation:

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

- >頂級數組只有元素。這是另一個有17個元素的陣列。

+0

它只顯示數組中的最高值,但我需要nsarray中的所有17個數據,以便將其顯示在餅圖中 –

+0

您的數組只有最高值:另一個陣列。 – vikingosegundo

+0

對不起,我不能讓你正確 –

0

字典對象是否正確打印了17值?如果字典本身是正確的,則可能需要以不同的方式解析字典中的計數對象。

這可能是您的打印計數和錯誤格式的情況下,因爲它不會真的是一個漫長的無符號......因爲你將其轉換爲長簽名,編譯器不會顯示警告...

+0

count並不重要,只是爲了我添加的信息count,當我將這個數組添加到一個餅圖時,它會顯示錯誤,2013-07-15 19:11:45.959 SubhamDashboard [11363:c07] myPieClass.itemArray:( ( 「16291443.69」, 6621797, 5692671, 2477348, 2362607, 2281261, 886410, 848799, 762441, 706688, 497076, 492402, 188320, 124595, 96625, 62905,) ) 2013-07-15 19:11:45。960 SubhamDashboard [11363:c07]合計:1 –