我正在使用https://currencylayer.com/documentation,免费帐户的货币转换 API。我让用户输入输出货币,因此例如如果用户输入 SGD,它将显示 USD 到 SGD 的货币转换:"USDSGD":1.318504 \n获取该值的方法是使用动态反序列化器,并将其放入一个标签。像这样:
\n\n lblResult.Text=test.quotes.USDSGD.ToString();\nRun Code Online (Sandbox Code Playgroud)\n\n但我想要的是无论用户选择的货币如何都能得到结果。另一个始终是美元,因此我\xe2\x80\x99d 喜欢将其与用户输入货币结合起来,以从 API 获取正确的值,例如:
\n\nvar propertyName = "USD" + destinationCurrencyName; // "USDSGD"\nlblResult.Text=test.quotes.{propertyName}; // what I\'d like\nRun Code Online (Sandbox Code Playgroud)\n\n在这里我将访问属性“USDSGD”。
\n\n我知道我可以使用反射(在 C# 中使用反射从字符串获取属性值),但这似乎有点矫枉过正。
\n\n这是查询返回的内容:
\n\n{\n "success":true,\n "terms":"https:\\/\\/currencylayer.com\\/terms",\n "privacy":"https:\\/\\/currencylayer.com\\/privacy",\n "timestamp":1517629571,\n "source":"USD",\n "quotes":{\n "USDSGD":1.318504\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的代码 - 强类型版本确实产生了预期的结果,但我想quotes从文本框中读取货币名称(本质上是元素的属性名称):
protected void btnConvert_Click(object sender, EventArgs e)\n{\n string convertTo = TextBox1.Text.ToString();\n var webRequest = (HttpWebRequest)WebRequest.Create("http://apilayer.net/api/live?access_key=MY_ACCESS_KEY¤cies=" + Server.UrlEncode(convertTo) + "&source=USD&format=1");\n var webResponse = (HttpWebResponse)webRequest.GetResponse();\n if …Run Code Online (Sandbox Code Playgroud) 我希望文本在我的图像上看起来像这样:
它稍微远离图像的“中心”点(因为我想避免图像中的电话),因此文本中心不起作用。我目前将行的划分设置为“相对”,将文本设置为“绝对”,以便将文本置于图像顶部。但是当我调整图像大小时,它会被移位。
代码:
<section>
<div class="col-lg-12 text-center"style="margin: 0;padding: 0;position: relative;">
<img class="img-fluid" style="width:100%;" src="img/phone-transparent.png" alt=""></img>
<h2 style="color:red;position: absolute; top: 120px; width: 100%;">This is also</br>available on your mobile.</h2>
</div>
</section>
Run Code Online (Sandbox Code Playgroud)