C
C#2y ago
itgel9462

❔ Can I use JSON file that came from Javascript in C#.

If so, what method should I use?
17 Replies
TheBoxyBear
TheBoxyBear2y ago
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
itgel9462
itgel9462OP2y ago
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.
Angius
Angius2y ago
You mean the result_ object? $jsongen
MODiX
MODiX2y ago
Use https://app.quicktype.io or https://json2csharp.com to generate classes from your JSON
Instantly 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.
Angius
Angius2y ago
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 class
itgel9462
itgel9462OP2y ago
Thank 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?
Angius
Angius2y ago
ye
itgel9462
itgel9462OP2y ago
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.
Angius
Angius2y ago
Do you have some API made with C# running? If not, then start there
itgel9462
itgel9462OP2y ago
I have. but API with C# is not real time voice recognition. I needed this one.
Angius
Angius2y ago
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
itgel9462
itgel9462OP2y ago
My task is print out the result that gets from this html file in C#
Angius
Angius2y ago
And you need to get it to C# somehow
itgel9462
itgel9462OP2y ago
and I thought the easier way to do this is JSON.
Angius
Angius2y ago
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
itgel9462
itgel9462OP2y ago
Thank you so much.
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server