我的 azure 函数有以下 JSON 输入,但在反序列化对象后无法将其传入
{
"name": [{
"SiteName": "Site1",
"SiteUrl": "https://site1.com/"
},
{
"SiteName": "Site2",
"SiteUrl": "https://site2.com/"
},
]
}
在反序列化后我得到计数为 2 但内部数组值我没有使用下面的代码反序列化
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
var Root = data["name"].ToObject<List<Constant>>();
和如下声明的常量类
class Constant
{
public Dictionary<string, string> name { get; set; }
}
最佳答案
尝试创建如下类。
class JsonResponse
{
public List<Constant> name { get; set; }
}
class Constant
{
public string SiteName { get; set; }
public string SiteUrl { get; set; }
}
并尝试使用 JsonConvert.DeserializeObject<JsonResponse>(requestBody)
反序列化响应.
string requestBody = new StreamReader(req.Body).ReadToEnd();
JsonResponse data = JsonConvert.DeserializeObject<JsonResponse>(requestBody);
var Root = data.name;
关于c# - 无法将 JSON 数组用于 Azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70936316/