Crash during deserialision json to protocol buffers in Objective C

ساخت وبلاگ

Vote count: 0

This is the code I am using to get a json object

NSString *requestString = @"http://url/joual/";
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:requestString]];
NSError* error;
NSArray *jsonDataArray = [[NSArray alloc] initWithArray:[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]];
NSDictionary *dictObject = [jsonDataArray objectAtIndex:1];
//NSLog(@"%@", [dictObject valueForKey:@"deviceA"]);
NSData *jsonJobData = [NSJSONSerialization dataWithJSONObject:dictObject options:kNilOptions error:&error];
JoualEntry *aJobEntry = [JoualEntry parseFromData:jsonJobData];

The jsonDataArray after serialization is

 ( { callGroupId = 1458762093348; callType = "NOT_RESPONDING"; callerInfoB = ( { firstName = ""; lastName = M5T2; } ); createdTime = 1460633282; deviceA = "++30(210)3453-342"; deviceB = 109; direction = INCOMING; duration = 0; }, { callGroupId = 1458762093361; callType = "NOT_RESPONDING"; callerInfoB = ( { firstName = ""; lastName = M5T5; } ); createdTime = 1460634071; deviceA = "+30(210)3453-342"; deviceB = 108; direction = INCOMING; duration = 0; }
)

I am using protobuf.io for objective c and I want to save those two joual entries to a protobuf generated class. However my code is crashing when I am trying to map json to objective c.

It is possible to read the json contents for example [dictObject valueForKey:@"deviceA"] retus correct data, however when I am trying to use parseFromData the app crashes and more specifically throws an exception here:

- (void) checkLastTagWas:(SInt32) value { if (lastTag != value) { @throw [NSException exceptionWithName:@"InvalidProtocolBuffer" reason:@"Invalid End Tag" userInfo:nil]; }
}

What I am doing wrong? Is the json file OK?

asked 3 mins ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 216 تاريخ : چهارشنبه 5 خرداد 1395 ساعت: 17:00