17 using Newtonsoft.Json;
18 using Newtonsoft.Json.Linq;
33 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
38 if (candlestick ==
null)
43 writer.WriteStartArray();
45 writer.WriteValue(candlestick.LongTime);
46 writer.WriteValue(candlestick.Open);
47 writer.WriteValue(candlestick.High);
48 writer.WriteValue(candlestick.Low);
49 writer.WriteValue(candlestick.Close);
51 writer.WriteEndArray();
57 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
59 if(reader.TokenType == JsonToken.StartObject)
61 var chartPoint = serializer.Deserialize<
ChartPoint>(reader);
62 if(chartPoint ==
null)
66 return new Candlestick(chartPoint.X, chartPoint.Y, chartPoint.Y, chartPoint.Y, chartPoint.Y);
68 var jArray = JArray.Load(reader);
71 var chartPoint = jArray.ToObject<
ChartPoint>();
72 if (chartPoint ==
null)
76 return new Candlestick(chartPoint.X, chartPoint.Y, chartPoint.Y, chartPoint.Y, chartPoint.Y);
78 return new Candlestick(jArray[0].Value<long>(), jArray[1].Value<decimal?>(), jArray[2].Value<decimal?>(),
79 jArray[3].Value<decimal?>(), jArray[4].Value<decimal?>());