有没有办法在php中删除发布的变量,或者通过swift以不同的方式发送它,这样关键字optional是不是围绕变量?
例如:
$username = $_POST['username'];
$query = "SELECT username from users where username = '".$username."' ";
//when echo query output is: SELECT username from users where username = 'Optional("t")'
//I need to remove Optional so query outputs:
// "SELECT username from users where username = 't'
我在swift中输入参数如下:
var post:NSString = "username=\(username)"
NSLog("PostData: %@",post);
答案 0 :(得分:0)
你可以这样做:
Dictionary<string, MyObject> objectDict = new Dictionary<string, MyObject>();
foreach (CSVEntry csvEntry in csvEntries)
{
MyObject obj = csvEntry.ToMyObject();
if (objectDict.ContainsKey(obj.UniqueKey))
{
objectDict[obj.UniqueKey] = obj;
}
else {
objectDict.Add(obj.UniqueKey, obj);
}
}
但是,如果由于某种原因var post: NSString = "username=\(username!)"
为零,那么您的应用程序将崩溃。您可以将其包围在username
中以避免这种情况。