/// <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.GoodBeamDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.GoodBeamDataSet}(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 GoodBeamDataSet(DataSet.Ensemble.DATATYPE_INT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.GoodBeamID); data.GoodBeamData = new int[NumElements, ElementsMultiplier]; // Decode the 2D array JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_GOODBEAMDATA]; 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.GoodBeamData[bin, beam] = (int)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.GoodBeamDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.GoodBeamDataSet}(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 GoodBeamDataSet(DataSet.Ensemble.DATATYPE_INT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.GoodBeamID); data.GoodBeamData = new int[NumElements, ElementsMultiplier]; // Decode the 2D array JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_GOODBEAMDATA]; 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.GoodBeamData[bin, beam] = (int)arrayData[beam]; } } } } return data; } return null; }