【问题标题】:Warning: string is not a string literal(potentially insecure) for code警告:字符串不是代码的字符串文字(可能不安全)
【发布时间】:2015-04-10 06:34:07
【问题描述】:

我是iOS初学者,谁能帮帮我:
我收到警告:string is not a string literal (potentially insecure) 以下代码

-( void )gettingEntitySchemaForGivenKayValueFromDataBase:( RequestType )requestType ParamDict:( NSDictionary * )parameterDict
    {
        PersistenceFromDataBase *persistanceDataObj=[ PersistenceFromDataBase sharedInstance ];
        //[ NSJSONSerialization dataWithJSONObject:[ persistanceDataObj getEntitySchemaForGinvenEntityIs:parameterDict ] options:NSJSONWritingPrettyPrinted error:nil ];
        NSDictionary  *dataDict= [ persistanceDataObj getEntitySchemaForGinvenEntityIs:parameterDict ];
        id datatoserialize=[ dataDict objectForKey:VIEWS_KEY ];
        NSLog([ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil ])
    ;
        NSLog(@" entitySchemaForEntityId:%@",dataDict );
       // [[ NSNotificationQueue defaultQueue ]  enqueueNotification:[ NSNotification notificationWithName:ENTITYSCHEMANOTIFICATION object:nil userInfo:@{ USER_INFO:dataDict }] postingStyle:NSPostWhenIdle ];
        // sent view data to view controller



    }

【问题讨论】:

  • 您的第一个 NSLog 没有格式字符串,因此会出现警告。
  • ... 这意味着如果字符串包含百分比字符,它将产生垃圾,如果它包含 %s 或 %@,则可能会崩溃。

标签: ios objective-c


【解决方案1】:

您的NSLog 缺少格式说明符。改用这个:

NSLog(@"%@",[NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]) ;

【讨论】:

    【解决方案2】:

    对于您的代码NSLog([ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil ]),NSLog 实际上会打印一个字符串,并且需要一个字符串格式作为输入。

    函数dataWithJSONObject:options:error: 返回NSData 而不是NSString,因此会出现警告。

    你可以试试这个NSLog(@"%@",[ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]);

    【讨论】:

      【解决方案3】:

      更换你的

      NSLog([ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil ])
          ;
      

      跟下面一个

      NSLog(@"%@", [NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-29
        • 1970-01-01
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多