Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

let suppose i have json file like this

C#
{
"url": "http://google.com",
"Viewmodel": {
              "recipientId": 0,
              "firstName": null,
              "lastName": null
            }
}


but above json structure changing every time so i can not create class

so for i have tried bellow

What I have tried:

C#
//get the Json filepath
string file = Server.MapPath("~/App_Data/output.json");
//deserialize JSON from file
string stringobj = System.IO.File.ReadAllText(file);
JavaScriptSerializer ser = new JavaScriptSerializer();
Object o= ser.Deserialize<Object>(stringobj);
foreach (var item in o)
{
// print the property but how ?
// print the value but how?
}
Posted
Updated 15-Dec-16 21:31pm
v3
Comments
F-ES Sitecore 13-Dec-16 9:02am    
Try some of the suggestions here

http://stackoverflow.com/questions/16646451/looping-through-json-array-in-c-sharp

Or simply google, this is a frequently asked questions with lots of solutions.
Member 10419297 22-Dec-16 8:20am    
thanks its working

1 solution

Hi,

Please try the following :


var Json_list = (Dictionary<string, object>)json_serializer.DeserializeObject(stringobj);

foreach (var record in Json_list)
{
Console.WriteLine(record);
}

Hopefully it will help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900