如何在 ios 中从原始格式打印漂亮的响应请求
how to print response request in pretty from raw in ios
我就是这样出局的
2016-08-23 11:48:04.944 LogInPage[3340:45237] requestReply: {"account-token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjhmYjI3NDEwZGNkMjQ3ZTY5MTQ1YWE4ZGZhNzY1OWVlIiwiaWF0IjoxNDcxOTMzMDg0LCJleHAiOjE0NzE5MzQ4ODQsImF1ZCI6ImJhbmRvYnJhcy5yb2xsZm9yd2FyZC5uZXQiLCJpc3MiOiJSb2xsIEZvcndhcmQgTExDIiwic3ViIjoiYWNjb3VudDpjb25zdW1lcjpub3JtYWwifQ.4gkE6Qq1TXKEvU9wyBc3aS2L73866TwTxR0sC8mcqjg","consumer":{"id":"8fb27410dcd247e69145aa8dfa7659ee","date-joined":1471933084000,"reward-multiplier":0,"verified":false,"preferences":{"daily-journal":1,"followed":1,"bonus-rolls":1},"contacts":{"name":null,"phone":null}},"user":{"id":"33e4442e9fbc4188a50448864a0bdf20","email":"has@jvnj.co","password":null,"consumer-id":"8fb27410dcd247e69145aa8dfa7659ee","business-id":null,"admin-id":null}}16
我要这样输出
{
"account-token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjQ0NTk1OTI2ZDRhYzQyMjc4OTliMzBjODQ4NWMxMGZkIiwiaWF0IjoxNDcxOTMwODg4LCJleHAiOjE0NzE5MzI2ODgsImF1ZCI6ImJhbmRvYnJhcy5yb2xsZm9yd2FyZC5uZXQiLCJpc3MiOiJSb2xsIEZvcndhcmQgTExDIiwic3ViIjoiYWNjb3VudDpjb25zdW1lcjpub3JtYWwifQ._PmzVQ4GfoVX2QPBi6wBwslCX-IWV3jUL1lqXihAqW4",
"consumer": {
"id": "44595926d4ac4227899b30c8485c10fd",
"date-joined": 1471930888000,
"reward-multiplier": 0,
"verified": false,
"preferences": {
"daily-journal": 1,
"followed": 1,
"bonus-rolls": 1
}
,
"contacts": {
"name": null,
"phone": null
}
},
"user": {
"id": "504559b7c57f4a0e9d6453ad18d713e6",
"email": "yryi@uri.com",
"password": null,
"consumer-id": "44595926d4ac4227899b30c8485c10fd",
"business-id": null,
"admin-id": null
}
}
我的密码是
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"requestReply: %@%@", requestReply,postLength);
// NSLog(@"Request body %@", [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding]);
}] resume];
提前致谢
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&jsonError];
NSLog(@"Response = %@",json);
}] resume];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&jsonError];
NSArray *keys=[json allKeys];
NSArray *values=[json allValues];
NSString *milliseconds = [NSString stringWithFormat:@"%@",[[json objectForKey:@"consumer"] objectForKey:@"date-joined"]];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:([milliseconds longLongValue] / 1000)];
NSDateFormatter *datfrm = [[NSDateFormatter alloc] init];
[datfrm setDateFormat:@"dd/MM/yyyy"];
NSString *strDate = [datfrm stringFromDate:date];
NSLog(@"The date is - %@",strDate);
打印结果为
The date is - 23/08/2016
在我上面的代码中,我传递的选项是 zero.So 如果你将 选项作为零传递 你 得到不可变容器 。
It means that all arrays will be NSArrays, all Dictionaries will be NSDictionaries, all strings will be NSStrings, and so on, even if the original objects were mutable dictionaries, dictionaries, or strings.
一般
Immutable objects are generally safer (no need to worry about a value changing underneath you)
我就是这样出局的
2016-08-23 11:48:04.944 LogInPage[3340:45237] requestReply: {"account-token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjhmYjI3NDEwZGNkMjQ3ZTY5MTQ1YWE4ZGZhNzY1OWVlIiwiaWF0IjoxNDcxOTMzMDg0LCJleHAiOjE0NzE5MzQ4ODQsImF1ZCI6ImJhbmRvYnJhcy5yb2xsZm9yd2FyZC5uZXQiLCJpc3MiOiJSb2xsIEZvcndhcmQgTExDIiwic3ViIjoiYWNjb3VudDpjb25zdW1lcjpub3JtYWwifQ.4gkE6Qq1TXKEvU9wyBc3aS2L73866TwTxR0sC8mcqjg","consumer":{"id":"8fb27410dcd247e69145aa8dfa7659ee","date-joined":1471933084000,"reward-multiplier":0,"verified":false,"preferences":{"daily-journal":1,"followed":1,"bonus-rolls":1},"contacts":{"name":null,"phone":null}},"user":{"id":"33e4442e9fbc4188a50448864a0bdf20","email":"has@jvnj.co","password":null,"consumer-id":"8fb27410dcd247e69145aa8dfa7659ee","business-id":null,"admin-id":null}}16
我要这样输出
{
"account-token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjQ0NTk1OTI2ZDRhYzQyMjc4OTliMzBjODQ4NWMxMGZkIiwiaWF0IjoxNDcxOTMwODg4LCJleHAiOjE0NzE5MzI2ODgsImF1ZCI6ImJhbmRvYnJhcy5yb2xsZm9yd2FyZC5uZXQiLCJpc3MiOiJSb2xsIEZvcndhcmQgTExDIiwic3ViIjoiYWNjb3VudDpjb25zdW1lcjpub3JtYWwifQ._PmzVQ4GfoVX2QPBi6wBwslCX-IWV3jUL1lqXihAqW4",
"consumer": {
"id": "44595926d4ac4227899b30c8485c10fd",
"date-joined": 1471930888000,
"reward-multiplier": 0,
"verified": false,
"preferences": {
"daily-journal": 1,
"followed": 1,
"bonus-rolls": 1
}
,
"contacts": {
"name": null,
"phone": null
}
},
"user": {
"id": "504559b7c57f4a0e9d6453ad18d713e6",
"email": "yryi@uri.com",
"password": null,
"consumer-id": "44595926d4ac4227899b30c8485c10fd",
"business-id": null,
"admin-id": null
}
}
我的密码是
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"requestReply: %@%@", requestReply,postLength);
// NSLog(@"Request body %@", [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding]);
}] resume];
提前致谢
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&jsonError];
NSLog(@"Response = %@",json);
}] resume];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&jsonError];
NSArray *keys=[json allKeys];
NSArray *values=[json allValues];
NSString *milliseconds = [NSString stringWithFormat:@"%@",[[json objectForKey:@"consumer"] objectForKey:@"date-joined"]];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:([milliseconds longLongValue] / 1000)];
NSDateFormatter *datfrm = [[NSDateFormatter alloc] init];
[datfrm setDateFormat:@"dd/MM/yyyy"];
NSString *strDate = [datfrm stringFromDate:date];
NSLog(@"The date is - %@",strDate);
打印结果为
The date is - 23/08/2016
在我上面的代码中,我传递的选项是 zero.So 如果你将 选项作为零传递 你 得到不可变容器 。
It means that all arrays will be NSArrays, all Dictionaries will be NSDictionaries, all strings will be NSStrings, and so on, even if the original objects were mutable dictionaries, dictionaries, or strings.
一般
Immutable objects are generally safer (no need to worry about a value changing underneath you)