0

i have a Json

{
   "test1.png": "123",
   "image.png": "456",
   "pdffile.pdf": "789"
}

how can i convert to C# dictionary or table

Miami
  • 3
  • 1
  • 2
  • Did you review [this post](https://stackoverflow.com/questions/6620165/how-can-i-parse-json-with-c)? – Sercan Dec 16 '21 at 04:13

3 Answers3

0

How about this?

string serializedDic = @"{
   ""test1.png"": ""123"",
   ""image.png"": ""456"",
   ""pdffile.pdf"": ""789""
}";

Dictionary<string, string> dict = 
  JsonSerializer
  .Deserialize<Dictionary<string, string>>(serializedDic);
DCAggie
  • 144
  • 8
0

Use Newtonsoft Json library.

First, create your own class, with 3 properties name it as you want. Add JsonPropertyAttribute with name exactly same as 3 json property.

Then, just Deserialize your json file to get your object.

DungNH
  • 344
  • 2
  • 9
0

Use Newtonsoft Json library

string json = @"{
    "test1.png": "123",
    "image.png": "456",
    "pdffile.pdf": "789"
}";

var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Mehdi
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 16 '21 at 09:31