0
我有一個NSMutableDictionary,它包含用戶的詳細信息。我已經使用解析並從MutableDictionary中獲取數據。如何在iPhone中創建NSMutableArray中的NSDictionary?
feedDictionary是, {
"city = New York",
"phone = 111111",
"email = [email protected]",
"year = 1986",
"degree = Undergraduate"
}
我已經加入所有的值到FeedArray,我想以創建FeedArray.Because我已經在顯示的數據兩個字典部分表格視圖。所以表格部分的數據是 - 第1節 - [城市,電話,電子郵件]和第2節[年份,學位]。因爲如果數據中的任何一個都是零,那麼我不應該刪除該部分中的特定行。所以我想檢查數據,數據是否爲零。
編輯:
之前,我加入到FeedArray,我要檢查的字符串是零或不是。如果字符串爲零,那麼我不應該添加數組,如果數據不是零,那麼只添加到FeedArray。
[self isEmpty:[feedDictionary valueForKey:@"city"]]?:[feedArray addObject:[feedDictionary valueForKey:@"city"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"phone"]]?:[feedArray addObject:[feedDictionary valueForKey:@"phone"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"email"]]?:[feedArray addObject:[feedDictionary valueForKey:@"email"]]; //section1
[self isEmpty:[feedDictionary valueForKey:@"year"]]?:[feedArray addObject:[feedDictionary valueForKey:@"year"]]; //section2
[self isEmpty:[feedDictionary valueForKey:@"degree"]]?:[feedArray addObject:[feedDictionary valueForKey:@"degree"]]; //section2
-(BOOL) isEmpty :(NSString*)str{
if(str == nil || [[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0)
return YES;
return NO;
}
預期輸出,
我的陣列是5(
section1{
"city = New York",
"phone = 111111",
"email = [email protected]",
}
section2
{
"year = 1986",
"degree = Undergraduate"e"
}
) 那麼,如何可以創建字典用於可變數組。所以請指導我。
謝謝!
感謝您的回覆。但請看我最新的問題,並幫助我。謝謝。 – Pugal 2011-01-31 10:45:15