我使用GET JSON請求知道事務的狀態(檢查每5秒):如何將這些字符串轉換爲布爾值?
string webAddr = "https://shapeshift.io/txStat/" + textBox1.Text;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
var apiResponse = JsonConvert.DeserializeObject<TransactionStatus>(responseText);
}
if (TransactionStatus.status = "no_deposits")
{
label7.Text = "Pending..";
}
else if (TransactionStatus.status = "received")
{
label7.Text = "Received..";
}
else if (TransactionStatus.status = "complete")
{
label7.Text = "Completed !";
}
else
{
label7.Text = "...";
}
我的問題是,我無法檢查該字符串值,因爲它需要「布爾」。我怎樣才能改變這個布爾?或者有任何其他方法可以做我想要做的檢查?謝謝 !
你正在通過使用一個等號在你的'if'語句中賦值。更改'TransactionStatus.status = ...'到'TransactionStatus.status == ...' – mrogers
哈哈我很轉儲,謝謝! – EduardLula
我建議使用switch(TransactionStatus.status)而不是這個if if else if噩夢。 – Filburt