how to return json string from js function to c# object

Prathamesh Shende 376 Reputation points
2022-10-20T13:54:11.953+00:00

Hi,
How to return json string into c# object from js result using Ijsruntime in blazor wasm?
After that will parse json string to json format and put into list<string>

json string is like this -
[{"value":"jggkg"},{"value":"566"},{"value":"989"},{"value":"2235"},{"value":"656"},{"value":"56"}]

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,382 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,196 Reputation points
    2022-10-20T15:59:37.653+00:00

    server:

    public class MyResponse   
    {   
         public string? value {get; set;}   
    }   
    ....   
       
    await JS.InvokeAsync<MyResponse[]>("myJsFunction");   
    

    client:

    const myJsFunction = () => [{"value":"jggkg"},{"value":"566"},{"value":"989"},{"value":"2235"},{"value":"656"},{"value":"56"}];   
    
       
    

    note: you could just use {value: "some value"}

    0 comments No comments