因为我想在不同的剃须刀页面(page2)中使用page2。我希望AppState.json保存来自jsonDocument的数据,不确定要使用哪种数据类型。谢谢。
它表示不能将System.Text.Json.JsonDocument转换为字符串。
AppState.cs:
public string? json
{
get;
set;
}1.剃须刀:
private IBrowserFile _loadedFile;
private async Task OnInputFileChange(InputFileChangeEventArgs e)
{
_loadedFile = e.File;
var utf8Json = _loadedFile.OpenReadStream(maxAllowedSize: 1024 * 1024 * 10);
try
{
var jsonDocument = await JsonDocument.ParseAsync(utf8Json);
AppState.json = jsonDocument @* Which datatype should I be using *@
catch (JsonException ex)
{
Console.WriteLine(ex.Message);
}
}第2页剃须刀:
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JSRuntime.InvokeVoidAsync("Create", AppState.json);
}发布于 2022-10-08 16:56:32
将属性更改为:
public JsonDocument? json { get; set; }不要忘记添加using System.Text.Json;。
https://stackoverflow.com/questions/73998398
复制相似问题