首页 > 代码库 > C# DataContractJsonSerializer 处理Json

C# DataContractJsonSerializer 处理Json

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.ServiceModel.Web;
using System.IO;
namespace Json1
{
    class Program
    {
        [DataContract(Namespace = "http://blog.csdn.net/longhaoyou")]
        public class JsonData
        {
            [DataMember(Order = 0)]
            public string id { get; set; }
            [DataMember(Order=1)]
            public string name { get; set; }
        }

        public static string JsonToString<T>(T value)
        {
             var vStream=new MemoryStream();
             DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
             serializer.WriteObject(vStream, value);
             byte[] jsondata = http://www.mamicode.com/new byte[vStream.Length];>

C# DataContractJsonSerializer 处理Json