zoukankan      html  css  js  c++  java
  • 字符串转Json对象

    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; }
    }


    }

  • 相关阅读:
    个人博客
    个人博客
    5.4
    4.30
    4.29
    4.28
    4.27
    4.26
    4.25
    4.24
  • 原文地址:https://www.cnblogs.com/Robert-huge/p/5501215.html
Copyright © 2011-2022 走看看