我不能将NSMutableDictionary
值发布到Webservice Url
这是我的代码
NSMutableArray*MatcRegistraionGetArray=[PushSyncDBMANAGER RetrieveMATCHREGISTRATIONData:_competitionCode :_matchCode]; NSMutableArray*MatchTeamplayerDetailsGetArray=[PushSyncDBMANAGER RetrieveMATCHTEAMPLAYERDETAILSData:_matchCode];
NSMutableDictionary *PushDict =[[NSMutableDictionary alloc]init];
[PushDict setValue :MatcRegistraionGetArray forKey:@"MatcRegistraion"];
[PushDict setValue:MatchTeamplayerDetailsGetArray forKey:@"MatchTeamplayerDetails"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:PushDict options:kNilOptions error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"JSON String: %@",jsonString);
NSData* responseData = nil;
NSString *urlString = @"http://192.168.1.39:8096/CAPMobilityService.svc/PUSHDATATOSERVER";
NSURL *url=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
responseData = [NSMutableData data] ;
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
NSString *bodydata=[NSString stringWithFormat:@"%@",PushDict];
[request setHTTPMethod:@"POST"];
NSData *req=[NSData dataWithBytes:[bodydata UTF8String] length:[bodydata length]];
[request setHTTPBody:req];
NSURLResponse* response;
NSError* error = nil;
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"the final output is:%@",responseString);
但我得到了CAPScoringApp [1261:39009]的崩溃***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' JSON写入中的无效类型(InningsEventPushRecord)&#39 ;
+(NSMutableArray *)RetrieveMATCHREGISTRATIONData: (NSString *) COMPETITIONCODE :(NSString *) MATCHCODE{
NSMutableArray *MATCHREGISTRATIONArray=[[NSMutableArray alloc]init];
int retVal;
NSString *dbPath = [self getDBPath];
sqlite3 *dataBase;
const char *stmt;
sqlite3_stmt *statement;
retVal=sqlite3_open([dbPath UTF8String], &dataBase);
if(retVal ==0){
//(CASE WHEN MR.TEAMACODE='%@' THEN MR.TEAMBCODE ELSE MR.TEAMACODE END)
NSString *query=[NSString stringWithFormat:@"SELECT * FROM MATCHREGISTRATION WHERE COMPETITIONCODE='%@' AND MATCHCODE='%@'", COMPETITIONCODE,MATCHCODE];
NSLog(@"%@",query);
stmt=[query UTF8String];
if(sqlite3_prepare(dataBase, stmt, -1, &statement, NULL)==SQLITE_OK)
{
while(sqlite3_step(statement)==SQLITE_ROW){
NSLog(@"Success");
InningsEventPushRecord *record=[[InningsEventPushRecord alloc]init];
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
// [f numberFromString:
record.MATCHCODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
record.MATCHNAME=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
record. COMPETITIONCODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
record. MATCHOVERS=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
record. MATCHOVERCOMMENTS=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];
record. MATCHDATE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5)];
record. ISDAYNIGHT=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 6)];
record. ISNEUTRALVENUE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 7)];
record. GROUNDCODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 8)];
record. TEAMACODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 9)];
record. TEAMBCODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 10)];
record. TEAMACAPTAIN=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 11)];
record. TEAMAWICKETKEEPER=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 12)];
record. TEAMBCAPTAIN=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 13)];
record. TEAMBWICKETKEEPER=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 14)];
record. UMPIRE1CODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 15)];
record. UMPIRE2CODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 16)];
record. UMPIRE3CODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 17)];
record. MATCHREFEREECODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 18)];
//record. VIDEOLOCATION=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 19)];
record. MATCHRESULT=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 20)];
record. MATCHRESULTTEAMCODE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 21)];
record. TEAMAPOINTS=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 22)];
record. TEAMBPOINTS=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 23)];
record. MATCHSTATUS=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 24)];
record. RECORDSTATUS=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 25)];
record. CREATEDBY=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 26)];
record. CREATEDDATE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 27)];
record. MODIFIEDBY=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 28)];
record. MODIFIEDDATE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 29)];
record.ISDEFAULTORLASTINSTANCE=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 30)];
record.ISSYNC=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 32)];
[MATCHREGISTRATIONArray addObject:record];
}
}
sqlite3_finalize(statement);
sqlite3_close(dataBase);
}
return MATCHREGISTRATIONArray;
}
从Dbmanager我得到NsmutableArray然后我将可变数组值添加到NsMutableDictioanary我传递了Post the PushDict但是崩溃了。任何人都帮我解决了这个问题
答案 0 :(得分:0)
在NSObjcet
班级
-(NSDictionary *)MatchRegistrationPushRecordDictionary {
return [NSDictionary dictionaryWithObjectsAndKeys:MATCHCODE,@"MATCHCODE",MATCHNAME,@"MATCHNAME", COMPETITIONCODE,@"COMPETITIONCODE",MATCHOVERS,@"MATCHOVERS", MATCHOVERCOMMENTS,@"MATCHOVERCOMMENTS", MATCHDATE,@"MATCHDATE",ISDAYNIGHT,@"ISDAYNIGHT",ISNEUTRALVENUE,@"ISNEUTRALVENUE", GROUNDCODE,@"GROUNDCODE",TEAMACODE,@"TEAMACODE", TEAMBCODE,@"TEAMBCODE", TEAMACAPTAIN,@"TEAMACAPTAIN",TEAMAWICKETKEEPER,@"TEAMAWICKETKEEPER", TEAMBCAPTAIN,@"TEAMBCAPTAIN", TEAMBWICKETKEEPER,@"TEAMBWICKETKEEPER", UMPIRE1CODE,@"UMPIRE1CODE", UMPIRE2CODE,@"UMPIRE2CODE", UMPIRE3CODE,@"UMPIRE3CODE", nil];
}
并在dbmanager类中返回调用此字典