/// <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.RangeTrackingDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.RangeTrackingDataSet}(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 RangeTrackingDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.RangeTrackingID); // Number of beams data.NumBeams = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_NUMBEAMS]; // SNR JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_SNR]; data.SNR = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.SNR[x] = (float)jArray[x]; } // Range jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_RANGE]; data.Range = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.Range[x] = (float)jArray[x]; } // Pings jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_PINGS]; data.Pings = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.Pings[x] = (float)jArray[x]; } 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.RangeTrackingDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.RangeTrackingDataSet}(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 RangeTrackingDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.RangeTrackingID); // Number of beams data.NumBeams = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_NUMBEAMS]; // SNR JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_SNR]; if (jArray != null) { data.SNR = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.SNR[x] = (float)jArray[x]; } } // Range jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_RANGE]; if (jArray != null) { data.Range = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.Range[x] = (float)jArray[x]; } } // Pings jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_PINGS]; if (jArray != null) { data.Pings = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.Pings[x] = (float)jArray[x]; } } // Amplitude jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_AMPLITUDE]; if (jArray != null) { data.Amplitude = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.Amplitude[x] = (float)jArray[x]; } } // Correlation jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_CORRELATION]; if (jArray != null) { data.Correlation = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.Correlation[x] = (float)jArray[x]; } } // Beam Velocity jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_BEAMVEL]; if (jArray != null) { data.BeamVelocity = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.BeamVelocity[x] = (float)jArray[x]; } } // Instrument Velocity jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_INSTRVEL]; if (jArray != null) { data.InstrumentVelocity = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.InstrumentVelocity[x] = (float)jArray[x]; } } // Earth Velocity jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_RT_EARTHVEL]; if (jArray != null) { data.EarthVelocity = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.EarthVelocity[x] = (float)jArray[x]; } } return(data); } return(null); }