1

I have a JSON like this

"type" : "info", 
"gameid" : "info", 
"userid" : "info", 
"actions" : 
[ 
  { 
   "actid" : "info", 
   "type" : "info", 
   "amount" : "info", 
   "timestamp" : "info" 
  },                                      
], 
"i_gamedesc" : "{SystemID}:{GameType}", 
"hmac" : "..." 

And correpsonding c# code to this json like this

        [JsonProperty(PropertyName ="gameid")]
        public int gameId { get; set; }

        [JsonProperty(PropertyName = "userid")]
        public int userId { get; set; }

The problem is that i do not know how to convert actions JSON array filed like above code.Some help?

So_oP
  • 1,211
  • 15
  • 31

1 Answers1

4

First, you need to create a corresponding class which will represent object in actions array

public class Action
{
   [JsonProperty(PropertyName = "actid")]
   public string ActId { get; set; }

   public string Type { get; set; }

   public string Amount { get; set; }

   public string Timestamp { get; set; }
}

then you need to create List<Action> property inside your root class

public class Root
{
    [JsonProperty(PropertyName ="gameid")]
    public int GameId { get; set; }

    [JsonProperty(PropertyName = "userid")]
    public int UserId { get; set; }

    [JsonProperty(PropertyName = "actions")]
    public List<Action> Actions { get; set; }

    ... other properties ...
}
Darjan Bogdan
  • 3,780
  • 1
  • 22
  • 31