You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2019/04/17 10:38:54 UTC

[GitHub] [incubator-weex] myeveryheart opened a new issue #2333: [iOS][Dev-tool] App crash when JSDebug where weex version is 0.20.1

myeveryheart opened a new issue #2333: [iOS][Dev-tool] App crash when JSDebug where weex version is 0.20.1
URL: https://github.com/apache/incubator-weex/issues/2333
 
 
   In WeexSDK-WXUtility.m, there's 
   `+ (NSString *)JSONString:(id)object
   {
       if(!object) return nil;
       
       @try {
       
           NSError *error = nil;
           if ([object isKindOfClass:[NSArray class]] || [object isKindOfClass:[NSDictionary class]]) {
               NSData *data = [NSJSONSerialization dataWithJSONObject:object
                                                              options:NSJSONWritingPrettyPrinted
                                                                error:&error];
               if (error) {
                   WXLogError(@"%@", [error description]);
                   return nil;
               }
               
               return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
           
           } else if ([object isKindOfClass:[NSString class]]) {
               NSArray *array = @[object];
               NSData *data = [NSJSONSerialization dataWithJSONObject:array
                                                              options:NSJSONWritingPrettyPrinted
                                                                error:&error];
               if (error) {
                   WXLogError(@"%@", [error description]);
                   return nil;
               }
               
               NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
               if (string.length <= 4) {
                   WXLogError(@"json convert length less than 4 chars.");
                   return nil;
               }
               
               return [string substringWithRange:NSMakeRange(2, string.length - 4)];
           } else {
               WXLogError(@"object isn't avaliable class");
               return nil;
           }
           
       } @catch (NSException *exception) {
           return nil;
       }
   }`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services