Ravi Patel

Ravi Patel

  • 275
  • 6.8k
  • 1.4m

how to iterate the object and print the property and valu

Dec 13 2016 8:08 AM
Hi All,
 
 let suppose i have json file  like this  
 
 
{
"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 
//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?
}
 
 

Answers (3)