public string GetJsonString()
{
List<Product> products = new List<Product>(){
new Product(){Name="苹果",Price=5},
new Product(){Name="橘子",Price=5},
new Product(){Name="干柿子",Price=00}
};
ProductList productlist = new ProductList();
productlistGetProducts = 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; }
}
public static List<T> JSONStringToList<T>(this string JsonStr)
{
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<T> objs = SerializerDeserialize<List<T>>(JsonStr);
return objs;
}
public static T Deserialize<T>(string json)
{
T obj = ActivatorCreateInstance<T>();
using (MemoryStream ms = new MemoryStream(EncodingUTFGetBytes(json)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(objGetType());
return (T)serializerReadObject(ms);
}
}
string JsonStr = "[{Name:'苹果',Price:5},{Name:'橘子',Price:5},{Name:'柿子',Price:16}]";
List<Product> products = new List<Product>();
products = JSONStringToList<Product>(JsonStr);
foreach (var item in products)
{
ResponseWrite(itemName + ":" + itemPrice + "<br />");
}
public class Product
{
public string Name { get; set; }
public double Price { get; set; }
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有