我是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
}
答案 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]);