Read JSON file using C# [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am building a web application in ASP.NET and I am relatively really new to programming. I am very confused on how to read objects in a JSON file(using C#) and use them in web application. Any help will be very appreciated.

There are several ways to read in the JSON but the standard way would be to use a JSON serialiser to serialise the document into a c# class structure.
This works well when you know the structure of the json file. See NewtonSoft for a very well known JSON library. There are others out there if you want something different.
If you need to figure out what the structure of your document is, then you could also use a tool like QuickType which will create the c# class structure for you.
If you didn't know the structure of the file up front then you could still use the NewtonSoft library but would need to do a few extra steps and things tend to get tricky.
I am not sure this is within the scope of your question.

NewtonSoft (https://www.newtonsoft.com/json) library is great for this, I recommend taking a look at it, specifically:
https://www.newtonsoft.com/json/help/html/SerializeObject.htm
https://www.newtonsoft.com/json/help/html/DeserializeObject.htm
For examples of usage.

Recommend library: Newtonsoft.Json. It is so easy to use.

Related

C# object serialization safely and best methods? Anyone can give me ans? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Object serialization method ? I am creating my own arraylist serialization application.
Serialization is a huge topic. Without discussing lots of details about what your requirements are, only vague guidance is possible, in which case: by default, probably keep it simple and use generic things like JSON or XML; Json.NET has over 100 samples which are very reasonable for general-purpose scenarios. If you have specific requirements about size/performance/compatibility/capabilities/etc, then other tools or formats may be more appropriate. The only main rules are:
do not blindly use BinaryFormatter (or NetDataContractSerializer)
don't roll your own home-baked serialization format/code unless you know a lot about serialization and can explain why none of the myriad of pre-existing libraries won't work for your specific scenario

JSON and XML Serialization [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Can someone explain how to use JSON and XML Serialization to store and transfer data and generalized situations in which you would choose one over the other?
XML & JSON are not to be used to store data, but rather transfer data between different pages, forms or web services. That's what they were designed for in the first place.
Differences between JSON and XML:
Similarities:
Both JSON and XML are "self describing" (human readable)
Both JSON and XML are hierarchical (values within values)
Both JSON and XML can be parsed and used by lots of programming languages
Both JSON and XML can be fetched with an XMLHttpRequest
Differences:
JSON doesn't use end tag
JSON is shorter
JSON is quicker to read and write
JSON can use arrays
You can find several explanations and guides on both XML and JSON in the links below. Make sure you give them a brief read before deciding on your preferred approach.
To your original question, I would suggest storing your user information in a separated database. There are many options out there for you to go through and decide what fits you best, considering your initial requirements.
XML:
https://www.w3schools.com/xml/xml_whatis.asp
https://www.w3schools.com/xml/xml_usedfor.asp
JSON:
http://www.json.org/
https://www.w3schools.com/js/js_json_intro.asp
Source:
https://www.w3schools.com/js/js_json_xml.asp

Which one is best? convert datatable to json or xml? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I create two projects using dot net. I send some data from one project to another project. I already handled this using xml conversion. Now I think to convert this using json data. Which one is best?.
In most cases, json is better. Because it has less redundant text and more efficient to parse. And what's more, is's much easier to parse json in javascript so that building a web app is much more convenient.
On the other hand, XML is more readable than json. That might be the only advantage of XML in this case.
XML is more verbose, but in the other hand is pretty easy to read.
JSON is simpler but not so good to read.
If you will not have humans looking the data, maybe using JSON would be a better idea. Since its smaller and will be less of a burden in your network (If that is a problem).
The other way you could evaluate, is looking on serialization speed, and that will depend a lot on the library you are using.

Tool that transforms various input files to single output format [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm looking for a solution for a problem that seems quite common to me. But I can't find any directions.
The problem I'm having is that I receive multiple input files (xsl, xslx, csv, plain ascii) that I need to transform into one format. So I'm actually looking for a tool that can be configured to parse inputfiles and generate an outputfile in one format (preferably csv).
If such a tool doen't exist, then I will probably create one myself using Visual Studio/C#. Can anyone give me any directions to existing tools and/or C# coding examples that do similar things?
Thanks in advance!
Kind regards,
Paul
If you decide to write a parser parsing xls to CSV with C#, a nice example can be found here
http://www.c-sharpcorner.com/uploadfile/yuanwang200409/how-to-convert-xls-file-into-csv-file-in-C-Sharp/
This is not a direct answer to you question, but it may help. Here is a generalised solution for converting arbitary CSV to XML.
CSV-to-XML

How to convert AVI to 3gp in C#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is it possible to convert an AVI file to 3gp in C# ? If so how could I do this? Any ideas will be appreciated, thanks in advance.
It depends what you mean by "convert". Both 3GP and AVI are wrapper formats, so are you merely trying to change the container format, or do you want to re-encode the streams as well?
Either way, you should probably take a look at ffmpeg (Windows info). For simple cases (i.e. you have the file, want a single output file), you should probably consider it invoking it on the command-line (i.e. System.Diagnostics.Process), which is much easier (and doesn't involve any licensing issues). If you want to access libavcodec/libavormat programatically, I highly recommend skipping any .NET wrapper libs (they all are in different states of sucking; Tao being the best but that's not saying much) and instead writing a C++/CLI wrapper. I started doing this, and once I got my head around data marshalling, etc., and figured out how to build it (Part 1, Part 2), it wasn't too hard.
There is no really easy way to do it; my advice is to use ffmpeg, either through the use of a C# wrapper of by calling it externally. There seem to be several C# wrappers for ffmpeg (like this one) but they all seem to be in various stages of development and not really usable. Your only option is likely going to be by calling it externally.

Categories