I'm implementing a client/server between a tablet and a PC and I need to pass data back and forth. After doing some reading json looks like it may be a simple, defined interface to use. I'm using Newtonsoft.Json in my project.
My understanding is that unless it is defined as required in the schema, that each name/value pair doesn't have to be in each message. If this is true, I'm struggling with how to parse the json object after deserializing it to determine the names that were sent in the message.
For example, If I'm sending weather data and can send json data that looks like
{ "isRaining": false,
"isSnowing": false,
"temp": 50.0
}
If I always send all three, then I can create a class that has the same members and assign the data when I deserialize it.
public class Weather
{
public bool isRaining { get; set; }
public bool isSnowing { get; set; }
public float temp { get; set; }
}
Weather readWeather = JsonConvert.DeserializeObject<Weather>(data);
But I'd like to not have to send ALL the data each transmission. I really only want to know if something has changed, and then get only the temp name/value pair if the temp has gone up, if whether it's raining or snowing hasn't changed, I don't want to get that data.
It looks like that at least deserializing the data this way, I can't do a for each loop to see what names exist. Is there any way to do this? Or am I stuck sending all the data all the time?
I will be sending more data in my actual implementation, I only put three pairs here for simplicity.