How to read the Json data without knowing the Key value

前端 未结 1 505
耶瑟儿~
耶瑟儿~ 2021-01-22 10:53

I have a json data which comes as the input string. Now I need to update the existing Json data with the input Json data. In my case, I want to go through each key and match wit

相关标签:
1条回答
  • 2021-01-22 11:14

    See if this helps you, We can use Newtonsoft to deserialize unknown types and loop the keys and 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;
            }
    
    0 讨论(0)
提交回复
热议问题