0
我無法在目標c中創建字典。我得到的警告,無法在目標c中創建字典?
不兼容的整數指針轉換髮送到NSInteger的參數
下面是我的代碼。
NSString *tmpSessionID = [[[AppSettings sharedAppSettings] getUserSession] objectForKey:@"UserSessionId"];
int tmpRepoId = [[[[AppSettings sharedAppSettings] getUserRepository] objectForKey:@"RepositoryId" ]intValue];
int tmpUserID = [[[[AppSettings sharedAppSettings] getUserSession] objectForKey:@"UserId"]intValue];
NSDictionary * fmDic = [[AppSettings sharedAppSettings] getFolderModel];
int containerId = containerId = [[fmDic objectForKey:@"ContainerId"]intValue];
int docTypeId = selectedDcoumentType.docTypeId;
NSDictionary *metaData = [[NSDictionary alloc] initWithObjectsAndKeys:
selectFileIndices.columnId, @"ColumnId",
indexValue, @"Value",
nil];
NSMutableArray *metaArray = [[NSMutableArray alloc]init];
[metaArray addObject:metaData];
NSDictionary *metaDataFiellds = [[NSDictionary alloc] initWithObjectsAndKeys:
metaArray, @"metaDataFields",
nil];
NSDictionary *allImportDict = [[NSDictionary alloc] initWithObjectsAndKeys:
containerId, @"containerId",
docTypeId, @"docTypeId",selectFileIndices.transText, @"fileExt",metaDataFiellds, @"metaDataFields",tmpRepoId, @"repositoryId",1, @"pagesCount",
tmpSessionID, @"sessionId", @"1487918350642.jpg", @"title",guid, @"tmpFileName",tmpUserID, @"userId",
nil];
NSLog(@"dictionary is %@",allImportDict);
我想創建一個JSON象下面這樣:
{
"containerId": 2,
"docTypeId": 1,
"fileExt": ".jpg",
"metaDataFields": [
{
"ColumnId": 1,
"Value": "23"
}
],
"pagesCount": 1,
"repositoryId": 1,
"sessionId": "1587c3c9-f261-4749-ace4-c134d031ec38",
"title": "1487918350642.jpg",
"tmpFileName": "5f8a0340-bd65-476c-b377-67fa19121203",
"userId": 5
}
哪條線你得到了錯誤 – iOS
NSDictionary不能存儲標量值(比如BOOL,NSInteger等),它只能存儲對象。你必須將你的標量值封裝到NSNumber中才能存儲它們:[NSNumber numberWithInteger containerId] – iOS
你知道沒有人像現在這樣寫Objective-C。你聽說過字典文字或下標訪問嗎? – deadbeef