/// <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.CorrelationDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.CorrelationDataSet}(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 CorrelationDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.CorrelationID); data.CorrelationData = new float[NumElements, ElementsMultiplier]; // Decode the 2D array JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_CORRELATIONDATA]; if (jArray.Count <= NumElements) // Verify size { for (int bin = 0; bin < jArray.Count; bin++) { JArray arrayData = (JArray)jArray[bin]; if (arrayData.Count <= ElementsMultiplier) // Verify size { for (int beam = 0; beam < arrayData.Count; beam++) { data.CorrelationData[bin, beam] = (float)arrayData[beam]; } } } } 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.CorrelationDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.CorrelationDataSet}(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 CorrelationDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.CorrelationID); data.CorrelationData = new float[NumElements, ElementsMultiplier]; // Decode the 2D array JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_CORRELATIONDATA]; if (jArray.Count <= NumElements) // Verify size { for (int bin = 0; bin < jArray.Count; bin++) { JArray arrayData = (JArray)jArray[bin]; if (arrayData.Count <= ElementsMultiplier) // Verify size { for (int beam = 0; beam < arrayData.Count; beam++) { data.CorrelationData[bin, beam] = (float)arrayData[beam]; } } } } return data; } return null; }