已解决,感谢G大哥和其他朋友。
using System.Runtime.Serialization;using System.IO;using System.Runtime.Serialization.Json;using System;using System.Text;using Newtonsoft.Json;using System.Collections.Generic;public class JsonDemo{ static void Main() { string json = @"{ ""error"" : 0 , ""flightData"" : { ""CA1503"" : { ""LowPrice"" : 985, ""HighPrice"" : 1350, ""pc"" : 5, ""fp"" : 5, ""priceData"" : { ""135"": { ""sn"" : 135, ""ins"" : 20, ""pp"" : 985, ""bi"" : ""baidu"", ""dis"": 6.5, ""cb"": ""R"", ""ut"" : 5 } } } } }"; //Console.WriteLine(json); FlightInformation flight = JsonHelper.Deserialize<FlightInformation>(json); Console.WriteLine("flight info:" + flight.flightData["CA1503"].priceData["135"].ins.ToString()); Console.Read(); }}public class FlightInformation{ public int error { get; set; } public Dictionary<string, Flight> flightData { get; set; }}public class Flight{ public decimal LowPrice { get; set; } public decimal HighPrice { get; set; } public int pc { get; set; } public decimal fp { get; set; } public Dictionary<string, PlaneTicket> priceData { get; set; }}public class PlaneTicket{ public int sn { get; set; } public decimal ins { get; set; } public decimal pp { get; set; } public string bi { get; set; } public decimal dis { get; set; } public string cb { get; set; } public decimal ut { get; set; }}public class JsonHelper{ public static string ToJson<T>(T obj) { System.Web.Script.Serialization.JavaScriptSerializer script = new System.Web.Script.Serialization.JavaScriptSerializer(); return script.Serialize(obj); } public static T Deserialize<T>(string sJson) where T : class { System.Web.Script.Serialization.JavaScriptSerializer script = new System.Web.Script.Serialization.JavaScriptSerializer(); return script.Deserialize<T>(sJson); }}
- 5 回答
- 0 关注
- 405 浏览
添加回答
举报
0/150
提交
取消