Committed by
朱小军
修改大数据上传时数据格式非法无法序列化的容错
review by yincheng
Showing
1 changed file
with
17 additions
and
1 deletions
@@ -73,6 +73,15 @@ | @@ -73,6 +73,15 @@ | ||
73 | NSError *error = nil; | 73 | NSError *error = nil; |
74 | NSMutableDictionary *actualParameters = [NSMutableDictionary dictionaryWithDictionary:parameters]; | 74 | NSMutableDictionary *actualParameters = [NSMutableDictionary dictionaryWithDictionary:parameters]; |
75 | 75 | ||
76 | + BOOL isValid = [NSJSONSerialization isValidJSONObject:actualParameters]; | ||
77 | + if (!isValid) { //校验上传数据格式合法性,如果不是合法的json格式,不再上传并删除本地文件,故返回YES | ||
78 | + YALog(@"upload data dictionary is not valid json object"); | ||
79 | + if (block) { | ||
80 | + block(YES, nil); | ||
81 | + } | ||
82 | + return nil; | ||
83 | + } | ||
84 | + | ||
76 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:actualParameters options:0 error:&error]; | 85 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:actualParameters options:0 error:&error]; |
77 | if (error) { | 86 | if (error) { |
78 | YALog(@"json parsing, connot convert to json for: %@\n code: %zd\n reason: %@", actualParameters, [error code], [error localizedDescription]); | 87 | YALog(@"json parsing, connot convert to json for: %@\n code: %zd\n reason: %@", actualParameters, [error code], [error localizedDescription]); |
@@ -177,7 +186,14 @@ | @@ -177,7 +186,14 @@ | ||
177 | { | 186 | { |
178 | NSError *error = nil; | 187 | NSError *error = nil; |
179 | NSMutableDictionary *actualParameters = [NSMutableDictionary dictionaryWithDictionary:parameters]; | 188 | NSMutableDictionary *actualParameters = [NSMutableDictionary dictionaryWithDictionary:parameters]; |
180 | - | 189 | + BOOL isValid = [NSJSONSerialization isValidJSONObject:actualParameters]; |
190 | + if (!isValid) { //校验上传数据格式合法性,如果不是合法的json格式,返回错误 | ||
191 | + YALog(@"upload data dictionary is not valid json object"); | ||
192 | + if (block) { | ||
193 | + block(NO, nil); | ||
194 | + } | ||
195 | + return nil; | ||
196 | + } | ||
181 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:actualParameters options:0 error:&error]; | 197 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:actualParameters options:0 error:&error]; |
182 | if (error) { | 198 | if (error) { |
183 | YALog(@"json parsing, connot convert to json for: %@\n code: %ld\n reason: %@", actualParameters, (long)[error code], [error localizedDescription]); | 199 | YALog(@"json parsing, connot convert to json for: %@\n code: %ld\n reason: %@", actualParameters, (long)[error code], [error localizedDescription]); |
-
Please register or login to post a comment