the final line always throw a exception:"invalid key in JSON dictionary". I cant figure out why. I can print the "msg" dictionary.
NSDictionary* header = @{
@(udpVersion) : @"ver",
@(self.dataType) : @"type",
@(self.ack) : @"ack",
[WBUserMng sharedClient].getUserId : @"src",
};
NSDictionary* msg = @{
header:@"head",
self.payload:@"data",
};
NSError* error = nil;
return [NSJSONSerialization dataWithJSONObject:msg options:kNilOptions error:&error]
I think you have the wrong order of key and value in the new Objective C syntax for dictionary literals. It should probably be
NSDictionary* msg = @{
@"head" : header,
@"data" : self.payload
};
and the same for the header dictionary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With