【发布时间】:2018-05-30 12:20:48
【问题描述】:
是否可以使用字符串在数据类型之间进行转换?我正在编写一个接收以下 JSON 的 Azure 函数:
{
"data": "1",
"type": "int"
}
我想将“1”返回为 int。到目前为止我做了什么:
dynamic body = await req.Content.ReadAsStringAsync();
Data data = JsonConvert.DeserializeObject<Data>(body as string);
数据类:
public class Data
{
public string data { get; set; },
public string type { get; set; }
}
谢谢。
【问题讨论】:
-
你不需要
dynamic,ReadAsStringAsync返回一个字符串。 -
谢谢,我不知道。
-
为什么投反对票?
-
不是我,我不知道为什么是 DV。不过有一个提示,我建议您不要使用“数据”来命名所有内容,也不要使用“类型”。
-
谢谢,我会改改以提高o/的可读性。