Agaram Agaram - 4 months ago 14
iOS Question

I can't post my dictionary values

I Cant Post the

NSMutableDictionary
Values To Webservice Url

Here is My Code

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);


but i got the crash of CAPScoringApp[1261:39009] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (InningsEventPushRecord)'

+(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;
}


From Dbmanager i got the NsmutableArray then I add the Mutable Array Values into NsMutableDictioanary the i pass the Post the PushDict but Got crash.Anyone help me to solve this issues

Answer

Add this in NSObjcet Class

  -(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];
}  

and return call this dictionary in dbmanager class

Comments