c# - How to read the Json data without knowing the Key value -


i have json data comes input string. need update existing json data input json data. in case, want go through each key , match existing json data , update value of key input json data.

code retrive existing data

var existingjson = productrepository.listofprod.cast<jarray>().where(x => x["prodid"].tostring() == id.tostring()); 

after retrieving data existingjson below.

{     prodid:"1",     title:"c#",     author:"jeffy",     publisher:"xyz",     category:"microsoft"     } 

now need loop through every key comes input , match existing json key , update value of key.

input , after updating should this:

{ prodid:"1", title:"c#", author:"jeffy", publisher:"abcd", category:"microsfot basic .net development kit" } 

see if helps you, can use newtonsoft deserialize unknown types , loop keys , values.

string json = "{prodid:\"1\",title:\"c#\",author:\"jeffy\",publisher:\"xyz\",category:\"microsoft\"}";         jobject obj = jsonconvert.deserializeobject < jobject>(json);         var properties = obj.properties();         foreach (var prop in properties)         {             string key = prop.name;             object value = prop.value;         } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -