/// <summary> /// Read the JSON object and convert to the object. This will allow the serializer to /// automatically convert the object. No special instructions need to be done and all /// the properties found in the JSON string need to be used. /// /// DataSet.AncillaryDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.AncillaryDataSet}(encodedEns) /// /// </summary> /// <param name="reader">NOT USED. JSON reader.</param> /// <param name="objectType">NOT USED> Type of object.</param> /// <param name="existingValue">NOT USED.</param> /// <param name="serializer">Serialize the object.</param> /// <returns>Serialized object.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.Null) { // Load the object JObject jsonObject = JObject.Load(reader); // Decode the data int NumElements = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_NUMELEMENTS]; int ElementsMultiplier = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_ELEMENTSMULTIPLIER]; // Create the object var data = new AncillaryDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.AncillaryID); // FirstBinRange data.FirstBinRange = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_FIRSTBINRANGE]; // BinSize data.BinSize = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_BINSIZE]; // FirstPingTime data.FirstPingTime = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_FIRSTPINGTIME]; // LastPingTime data.LastPingTime = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_LASTPINGTIME]; // Heading data.Heading = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_HEADING]; // Pitch data.Pitch = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PITCH]; // Roll data.Roll = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_ROLL]; // WaterTemp data.WaterTemp = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_WATERTEMP]; // SystemTemp data.SystemTemp = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_SYSTEMP]; // Salinity data.Salinity = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_SALINITY]; // Pressure data.Pressure = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PRESSURE]; // TransducerDepth data.TransducerDepth = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_TRANSDUCERDEPTH]; // SpeedOfSound data.SpeedOfSound = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_SPEEDOFSOUND]; return(data); } return(null); }
/// <summary> /// Read the JSON object and convert to the object. This will allow the serializer to /// automatically convert the object. No special instructions need to be done and all /// the properties found in the JSON string need to be used. /// /// DataSet.AncillaryDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.AncillaryDataSet}(encodedEns) /// /// </summary> /// <param name="reader">NOT USED. JSON reader.</param> /// <param name="objectType">NOT USED> Type of object.</param> /// <param name="existingValue">NOT USED.</param> /// <param name="serializer">Serialize the object.</param> /// <returns>Serialized object.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.Null) { // Load the object JObject jsonObject = JObject.Load(reader); // Decode the data int NumElements = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_NUMELEMENTS]; int ElementsMultiplier = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_ELEMENTSMULTIPLIER]; // Create the object var data = new AncillaryDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.AncillaryID); // FirstBinRange data.FirstBinRange = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_FIRSTBINRANGE]; // BinSize data.BinSize = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_BINSIZE]; // FirstPingTime data.FirstPingTime = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_FIRSTPINGTIME]; // LastPingTime data.LastPingTime = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_LASTPINGTIME]; // Heading data.Heading = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_HEADING]; // Pitch data.Pitch = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PITCH]; // Roll data.Roll = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_ROLL]; // WaterTemp data.WaterTemp = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_WATERTEMP]; // SystemTemp data.SystemTemp = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_SYSTEMP]; // Salinity data.Salinity = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_SALINITY]; // Pressure data.Pressure = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PRESSURE]; // TransducerDepth data.TransducerDepth = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_TRANSDUCERDEPTH]; // SpeedOfSound data.SpeedOfSound = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_SPEEDOFSOUND]; return data; } return null; }