Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Tue Oct 13 15:13:11 CDT 2009
Continued.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Web.Script.Serialization;
namespace ConsoleApplication1
{
[XmlType("phoneBookEntry")]
public class PhoneBookEntry
{
[XmlAttribute("firstName")]
public string FirstName {get;set;}
[XmlAttribute("lastName")]
public string LastName { get; set; }
[XmlAttribute("phoneName")]
public string Phone { get; set; }
}
class Program
{
static void Main(string[] args)
{
PhoneBookEntry entry = new PhoneBookEntry();
entry.FirstName = "Peter";
entry.LastName = "Brown";
entry.Phone = "+7-921-1234567";
JavaScriptSerializer js = new JavaScriptSerializer();
string jsEntry = js.Serialize(entry);
Console.WriteLine("1. JSON string\n{0}", jsEntry);
PhoneBookEntry[] entries = { entry, entry, entry };
string jsEntries = js.Serialize(entries);
Console.WriteLine("1. JSON array\n{0}", jsEntries);
string xmlEntry =
InMemoryObjectsSerializer.Serialize<PhoneBookEntry>(entry);
Console.WriteLine("1. XML string\n{0}", xmlEntry);
string xmlEntries =
InMemoryObjectsSerializer.Serialize<PhoneBookEntry[]>(entries);
Console.WriteLine("1. XML array\n{0}", xmlEntries);
}
}
To be continued in part 3.