【发布时间】:2022-10-18 21:27:46
【问题描述】:
我正在使用 Azure 持久函数,但在使用 System.Text.Json 时遇到了一些问题 在真实场景中,我将有一个活动函数,它将调用一个 API 端点并获得一些 Json 结果,该结果将有一个具有多种类型(字符串和 int)的数组。
我将尝试描述问题。你知道修复它的方法吗?
所以我使用这个类将它反序列化为一个 C# 对象。
public class JsonTest
{
public dynamic[] Test { get; set; }
}
这是执行反序列化的示例活动函数。
[FunctionName("GetJson")]
public static JsonTest GetJson([ActivityTrigger] string id)
{
var jsonString = "{ \"Test\": [\"Fabrizio\", 39] }";
var result = JsonSerializer.Deserialize<JsonTest>(jsonString);
return result;
}
我可以看到它有效。
但是,一旦我将对象从 Activity Function 返回到 Orchestrator,就会出现问题。我已经没有价值观了。即使我尝试扩展它。我最终会得到一个错误。 它也使用 Newtonsoft.Json.Linq.JToken 但我不知道它有多相关,因为我只是使用 System.text.json
第一='(新 System.Linq.SystemCore_EnumerableDebugView<System.Collections.Generic.KeyValuePair<string, Newtonsoft.Json.Linq.JToken>>(foo.Test[0]).Items[0]).Value.First' 引发了“System.InvalidOperationException”类型的异常
【问题讨论】:
标签: c# json azure-functions system.text.json azure-durable-functions