2

I have a JSON result from external server

{
    "address": {
        "0": {
            "name": "House 1",
            "x": 1,
            "y": 2
        }
    }
}

how can I create correct class in C# for parsing ?

I tried to get class here http://json2csharp.com And then code

//first way
RootObject MyObject = JsonConvert.DeserializeObject<RootObject>(text);
// another way
dynamic d = JObject.Parse(text);

But null pointer raise every time. Thank you in advance.

Andrey Rybalkin
  • 206
  • 2
  • 11
  • try *JContainer data = (JContainer)Newtonsoft.Json.JsonConvert.DeserializeObject(text);* that will return a JContainer what is a class which will allow you to access the data like in a dictionary. – Gusman Feb 29 '16 at 10:19
  • Is there always *exactly* one address, always with the key "0"? It looks like you might want a dictionary... – Jon Skeet Feb 29 '16 at 10:21

1 Answers1

0

I found answer here (in Stackoverflow)

[JsonProperty(PropertyName = "0")]
public VJGeocenterSingle ZeroSingle { get; set; }

Excuse me for a newby question. My first step in JSON :)

Andrey Rybalkin
  • 206
  • 2
  • 11