亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

json反序列化的問題。

json反序列化的問題。

BIG陽 2018-12-07 02:06:36
已解決,感謝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 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

好的,我試試。試完了出結果。
查看完整回答
反對 回復 2019-01-21
?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

測試了一下,DataMember不做設置,序列化是通過了。 可以設計到的對象為null。沒有值 如果DataMember做Name設置就可以。 可以Name是變化的。
查看完整回答
反對 回復 2019-01-21
  • 5 回答
  • 0 關注
  • 439 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號