aderw
aderw

Reputation: 41

How to Serialize Dictionary<string[],int> to json using JsonConvert newtonsoft c#

Trying to serialize Dictionary<string[],int>

var requestData = new Dictionary<string, object>
{
   { "games" ,new Dictionary<string[],int> { {new string[] { "1000"}, 1 } } }
             
};

var data = JsonConvert.SerializeObject(requestData);

The output JSON looks something like {"games":{"(Array)":1}} which is not what I want. Info of string[] is gone

Upvotes: 1

Views: 224

Answers (1)

Serge
Serge

Reputation: 43939

Why don't use this:

var requestData = new Dictionary<string, object>
        {
         { "games",new Dictionary<int, string[]>{ {  1, new string[] { "1000", "2000"} } }
         }
       };

        var data = JsonConvert.SerializeObject(requestData);

it results

{"games":{"1":["1000","2000"]}}

Upvotes: 1

Related Questions