❔ Can I use JSON file that came from Javascript in C#.
If so, what method should I use?
17 Replies
Yes, json was designed for javascript but isn't actually tied to the language it was created in
System.Text.Json has everything you need to deserialize but you should recreate the model with classes
Thank you Sir. I'm totally new at these languages so I want to make sure something. This is the JSON file that shows as result on the Web browser. Could I convert this string text to C# by using System.Text.Json that you mentioned.
You mean the
result_
object?
$jsongenInstantly parse JSON in any language | quicktype
Whether you're using C#, Swift, TypeScript, Go, C++ or other languages, quicktype generates models and helper code for quickly and safely reading JSON in your apps. Customize online with advanced options, or download a command-line tool.
Convert JSON to C# Classes Online - Json2CSharp Toolkit
Convert any JSON object to C# classes online. Json2CSharp is a free toolkit that will help you generate C# classes on the fly.
You can generate C# classes from the JSON string you get
Then, as mentioned, use
System.Text.Json
namespace and JsonSerializer
class to deserialize that string into the generated classThank you so much. It's really hard to understand for me 😅 . But I'll try my best.
Sorry to bother you. Are you still here?
ye
It's still little complicated to understand. First of all, There are 4 files to get voice recognition. wrp.html is the file to get the result on web page like this picture (it's Japanese though). It's real time voice recognition so, JSON string only shows on the Web page. And i don't know how to link this JSON string to C# right away.
Do you have some API made with C# running?
If not, then start there
I have. but API with C# is not real time voice recognition. I needed this one.
Well... you need to get this JSON to C# somehow
With a request to the API for example
Or a websocket
Or SignalR connection
Or something
My task is print out the result that gets from this html file in C#
And you need to get it to C# somehow
and I thought the easier way to do this is JSON.
JSON is just the format of data
You can send JSON to an API
You can send it over websockets
You can send it over SignalR
You can save it to a file
JSON is no different from XML, Yaml, or CSV
Just a format
So, queston: how do you want to get that JSON into your C# code?
If it's a website, you'll need to send that data using one of the forementioned ways
If you use server-side JS with Node to generate a HTML file that contains JSON... why, just create a JSON file
Aight, I'm going to sleep. In the meantime, you think over how you want to move the data, exactly. Is it all happening on the server? Is the HTML and JS running in the browser and C# on the server? Can you use an API or it needs to be real-time? etc
Thank you so much.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.