0

Trying to figure out how to Serialize or Deserialize (JSON) an object, that has a value property that can be a bool, number, or string.

"object": {
  "id":"someID",
  "value": -10 or true or "someString"
}

I expect I will need to use JSONConvert, however I am not really finding how to do this with a Primitive DataType, all I can find is converting between a single object or an array of said object. This seems like it should be straight forward, for whatever reason, I just can't figure it out.

1
  • Just convert to object datatype Commented Nov 12, 2020 at 13:40

1 Answer 1

2

You can convert to object datatype, it can ben a number, string, list... You just have to handle it carefully.

    public class Object
    {
        [JsonProperty("id")]
        public string Id { get; set; }
        [JsonProperty("value")]
        public object Value { get; set; }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

That is kind of what I came up with, I figured there might be a better way. But I think I can run with this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.