JSON and XML Serialization [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 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

Related

Read JSON file using 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 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.

Which is better Binary Serialization or 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 8 years ago.
Improve this question
If i have a class that contains some string, int and List type properties and I want to store that class object into my physical disc. So, which method is better performance wise and file size wise.
There is no correct answer really. Performance-wise the binary method is faster and the file size will be smaller, XML well be slower to parse and will have a bigger size because of it adds "metadata" to describe things.
But it really a question of application, the XML is human-readable and more universal while the binary format depends on your implementation of it and cannot be read by others if they don't have your program/specification for this file (unless of course they reverse engineer it...)
Also binary format gives you more freedom in a matter of compression/encryption etc...
I agree with Jonathon and Urilil.
While binary is more efficient for performance and file size, I would not recommend to use it.
You will face two issues :
- i case of a bug, how do you know if the bug is in the write or in the read side ?
- when your class evolves (and it will), you might not be able to read old files whith last version of your application
So, use XML or JSON.
if you still need binary, have a look at protocol buffers
It actually depends on the context. If you have two applications using same data, you might use Binary Serialization which is faster but less flexible. But in case of different systems, like one in C# another in Python, XML serialization is more appropriate for its flexibility. And you have to keep performance issues in mind. So, there is always a tradeoff.

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.

C# Saving Objects [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 9 years ago.
Improve this question
I want to be able to save several objects which are linked each other. Idea is to have a Client object, Project object, Work object which will interfere each other. All data within will be as string and int. Everything will be joined in Record Object in which I will choose values from mentions object plus adding new entries.
What would be the best way to save all into a file - serialization? Is it possible to do it with some kind of data base? So far it is recorded in Excel table.
Serialization is fast and compact way to do it, but with linq you have XML and XML serialization which is closer to what you are looking for :
http://msdn.microsoft.com/en-us/library/bb387098.aspx
To go further Linq was created to simplify database queries so by default you will be able to access any ODBC compatible database (sqLite MySQL etc...)
FYI : You can Edit XML and XML scheme with Excel (if that's the kind of things your're into)

C# Parsing Best Practices [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to parse some known file formats, one of them is the CUSCAR format, i strongly believe that RegEx will do the job ,any suggestions ?
I just looked at the CUSCAR spec, and I think you'll get some pretty ugly regex code to parse that. You could get away with it, if you are parsing only part of it. You'll have to test for speed, as your main bottleneck will be I/O.
I did something similar with the vendor files that came from QWEST. These beasties were hierarchical text files. Parsing those sucked! I'm currently creating and parsing text files between 4 to 50 million lines each (every day).
There is a nice framework called FileHelpers Library. This framework will help you create object-oriented representation of the records (text lines). It even has a nice wizard to walk you through the creation of these objects representing the records. It will handle master-detail, delimited, and fixed formats easily.

Categories