警告:字符串不是代码的字符串文字(可能不安全)

时间:2015-04-10 06:34:08

标签: ios objective-c

我是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



    }

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

函数dataWithJSONObject:options:error:返回NSData而非NSString,因此警告。

您可以尝试使用NSLog(@"%@",[ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]);

答案 2 :(得分:0)

替换

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

以下一个

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