0

I get answer in JSON format from server like this (uid1, uid2...uidN - is dynamically named fields from server):

{
   "get_message_state":
   {
      "uid1":"some text 1",
      "uid2":"some text 2",
      ...
      "uidN":"some text N"
   },
   "status":"OK_Operation_Completed"
}

When I try to describe a class to deserialize json response from server, i have a problem with get_message_state field. How to describe this field in class?

public class MessageStateResponse
{
   [JsonProperty(PropertyName = "status", Order = 2)]
   public string Status { get; set; }
   [JsonProperty(PropertyName = "get_message_state", Order = 1)]
   public Msg MessageState { get; set; } //??????????
}

public class Msg
{
   [JsonProperty]
   public Dictionary<string, string> Fields { get; set; } //??????????
}
4
  • 1
    Which error are you getting? Commented Apr 3, 2014 at 8:37
  • @mitomed if used code in first message, I don't have any errors, but get_message_state -> Fields is null Commented Apr 3, 2014 at 9:02
  • Are you using Json.Net? There are quite a few answers that may help you if you refine the search, for example this one stackoverflow.com/questions/19434500/… Otherwise could you put how you're using it? Commented Apr 3, 2014 at 9:17
  • @mitomed thanks for the link, I found the answer to my question Commented Apr 3, 2014 at 9:59

1 Answer 1

1

You don't have to wrap dictionary to Msg object.

public class MessageStateResponse
{
   [JsonProperty(PropertyName = "status", Order = 2)]
   public string Status { get; set; }
   [JsonProperty(PropertyName = "get_message_state", Order = 1)] 
   public Dictionary<string, string> Fields { get; set; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I rewrite my code like this, it works. Thanks.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.