I'm having a similar problem as posted here Except I'm using an Azure Mobile App Service Backend. I have json string stored in the sql database and I need the App Service to de-serialize it to the object type.
Currently the Json from the Azure Mobile App Service Get looks like this: (and this isn't the in-code formatting, it's actually formatting the json that way)
{"deleted": false,"updatedAt": "2020-06-09T16:30:48.09Z","createdAt": "2020-06-03T04:34:41.617Z","version": "AAAAAABXrYA=","id": "DBEC6DE9-3C5C-47C5-8404-67C79FCF6740","equipmentSpeakerTapValue": "{\"value\": 0.0,\"wattage\": 0,\"direct\": false}"}
equipmentSpeakerTapValue is shown as a string an not a json nested object
I need the Json to look like this:
{"deleted": false,"updatedAt": "2020-06-09T16:30:48.09Z","createdAt": "2020-06-03T04:34:41.617Z","version": "AAAAAABXrYA=","id": "DBEC6DE9-3C5C-47C5-8404-67C79FCF6740","equipmentSpeakerTapValue":{"Value":2.5,"Wattage":70,"Direct":false}"}
Since I'm using Azure Mobile App Service I don't know if the problem is with the Entity Framework or the Json Serializing/DeSerializing. I also don't know how to change it since Azure Mobile App Service is a wrapper so you can't do things normally.
Here is my EF object model and the model of what I need the string property to deserialize to:
public class SiteEquipment
{
public string Id { get; set; }
public byte[] Version { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public bool Deleted { get; set; }
//I don't know which EquipmentSpeakerTapValue to use:
//string version that serializes to: "equipmentSpeakerTapValue": "{\"value\": 0.0,\"wattage\": 0,\"direct\": false}"
public string EquipmentSpeakerTapValue { get; set; }
//object version that should serialize to: "equipmentSpeakerTapValue":{"Value":2.5,"Wattage":70,"Direct":false}"
public TapValue EquipmentSpeakerTapValue { get; set; }
}
public class TapValue
{
public double Value { get; set; }
public int Wattage { get; set; }
public bool Direct { get; set; }
}