the sample is a json object, a json array would be:
var json = JsonSerializer.Serialize(new object[] {errors, product});
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I'm developing a Blazor Server application and I "declared" this EndPoint in the "Configure" of the Startup.cs file:
endpoints.MapGet("/products/GetProduct/{ProductType}/{ProductSerialNumber}", (context) =>
{
string ProductType = Convert.ToString(context.GetRouteValue("ProductType"));
string ProductSerialNumber = Convert.ToString(context.GetRouteValue("ProductSerialNumber"));
(var product , var errors) = app.ApplicationServices.GetService<ProductsServices>().GetProduct(ProductType, ProductSerialNumber);
var json = JsonSerializer.Serialize<Product>(product);
return context.Response.WriteAsync(json);
});
How can I get the "errors" object back too? is it possible to manage the return of two or more objects?
Best
Stefano
the sample is a json object, a json array would be:
var json = JsonSerializer.Serialize(new object[] {errors, product});
just depends on what you want the response json to look like. do you want an array, or object, try:
var json = JsonSerializer.Serialize(new {errors = errors, product = product});
Hi,
thanks for the reply. Your solution works (an and array)
it would be better as an object, in this case how is the syntax?
Best
Stefano