Reputation: 63
is there a way to convert JSON file into a C# list without using a helper class ?
i have read some articl about using Dynamics, but i don't know how to loop through items inside dynamic object.
here what i have found so far :
StreamReader r = new StreamReader(@"C:\Users\barras\Desktop\P922 test File\Itacc_Files\OpenNet_P922x_NM_31698.json");
string jsonString = r.ReadToEnd();
dynamic JsonDyn= Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString);
now, i need to loop through each item in dynamic object JsonDyn and fill the data into a list.
here Json File structure :
{
"OpenNet_PoGnd":
{
"Pins": ["CBGND_1","CBD_7","CT2_4","CBD_6" ]
},
"OpenNet_L36":
{
"Pins": ["CBF_22","CBF_9"]
},
"OpenNet_L37":
{
"Pins": ["CT2_1","CBF_20","CT1_2","CBF_18"]
},
"OpenNet_IC104":
{
"Pins": ["CN5_4","CBC_40"]
},
......
}
Upvotes: 1
Views: 1148
Reputation: 263
try this :
dynamic array = JsonConvert.DeserializeObject(jsonString );
foreach(var item in array)
{
String Str = item.Pins;
}
Upvotes: 1