using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
namespace JsonTest
{
class Program
{
static void Main(string[] args)
{
string json = GetJsonString();
Console.WriteLine(json);
Console.ReadKey();
}
private static string GetJsonString()
{
List<Product> products = new List<Product>()
{
new Product(){Name="苹果",Price=5.5},
new Product(){Name="橘子",Price=2.5},
new Product(){Name="干柿子",Price=16.00}
};
ProductList productlist = new ProductList();
productlist.GetProducts = products;
return (new JavaScriptSerializer().Serialize(productlist));
}
}
public class Product
{
public string Name { get; set; }
public double Price { get; set; }
}
public class ProductList
{
public List<Product> GetProducts { get; set; }
}
}