1

I have the following JSON which is serialized from a hashset Hashset<RootObject,List<Messages>>

{
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": [],
  "GasmonConsole.RootObject": []
}

Where RootObject is

public class RootObject
{
    public double x { get; set; }
    public double y { get; set; }
    public string id { get; set; }
}

I am using JSON.NET like this: string json = JsonConvert.SerializeObject(tracker,Formatting.Indented); to serialize the Hashset.

The values exports perfectly when I fill this hashset with data but the headers(Key in the sash) where it says "GasmonConsole.RootObject"isn't useful as it doesn't allow me to identify which object is which. I have tried some of the examples I think relate to my issue on the JSON.NET documentation but none of them see to work.

I am looking to have the headers be the ID of the RootObject (example below) but as I said I have tried the example above and it didn't work. Is this possible and if so could someone please point me in the right direction?

{
  "111": [],
  "112": [],
  "113": []
}

I also apologize if header is the wrong term to refer to these values as.

Thanks!

1 Answer 1

1

It looks like you only need the Id mapper with the collection of messages. If that's the case then you should pass the following for Deserialization:

Hashset<int,List<Messages>>

while the key would the RootObject's Id property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.