7

I always find very sophisticated way to serialize all kind of objects, lists and who knows, But I can't seem to find a simple way to serialize an array.

(I found one, but its serializing the array to a binary file, and I need to be able to edit the serialized file in any regular text editor [It's a language file, I need to give copies to my co-workers so they can translate the file into other languages/])

1
  • 1
    Uhm,... you need it to be human-readable? Why not use JSON-like syntax for the serialization? Or XML? Commented Dec 5, 2010 at 17:24

5 Answers 5

13

Assuming your array is an array of strings...

using (var stream = File.Create("file.xml")) {
    var serializer = new XmlSerializer(typeof(string[]));
    serializer.Serialize(stream, someArrayOfStrings);
}

Will create a simple XML file that is very easy to understand/modify. To deserialize it, use the Deserialize method.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you bring an example of deserializtion?
6

Human readable? I'd go for JavaScriptSerializer; just:

string json = new JavaScriptSerializer().Serialize(arr);

Comments

2

It's a language file, I need to give copies to my co-workers so they can translate the file into other language

XML Serialization is ideal it sounds like based on the above statement

Comments

2

If the serialized array needs to be portable and editable in a text editor, then you can use XML or Json to serialize

Comments

1

best way to learn is look at how it's done with a xsd that serialize into a xml

starting point

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.