<7b0a2020 22536372 65656e49 4422203a 20224c61 6e64696e 67506167 65564322 2c0a2020 22446576 69636549 4422203a 20224537 45463844 43452d43 4538412d 34463043 2d424243 352d4630 38304332 39464546 3239222c 0a202022 53657373 696f6e53 74617274 54696d65 22203a20 22323031 342d3033 2d323754 30373a31 343a3336 222c0a20 20225365 7373696f 6e456e64 54696d65 22203a20 22323031 342d3033 2d323754 30373a31 343a3336 220a7d>
请告诉我这种格式是什么,以及如何将其解码为String?
谢谢!
答案 0 :(得分:-1)
NSData *jsonData;
if ([NSJSONSerialization isValidJSONObject:dict]) {
NSError *error;
jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
if (!jsonData) {
NSLog(@"json Data %@",error.description);
} else {
NSString *JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
NSLog(@"JSON String %@",JSONString);//[JSONString dataUsingEncoding:NSUTF8StringEncoding]
[request setHTTPBody:jsonData];
}
}
else
{
NSLog(@"This Data can't be serialized");
}
jsonData将是:<7b0a2020 22536372 65656e49 4422203a 20224c61 6e64696e 67506167 65564322 2c0a2020 22446576 69636549 4422203a 20224537 45463844 43452d43 4538412d 34463043 2d424243 352d4630 38304332 39464546 3239222c 0a202022 53657373 696f6e53 74617274 54696d65 22203a20 22323031 342d3033 2d323754 30373a31 343a3336 222c0a20 20225365 7373696f 6e456e64 54696d65 22203a20 22323031 342d3033 2d323754 30373a31 343a3336 220a7d>