Get values and keys in json object using Json.Net C#

前端 未结 1 1765
天涯浪人
天涯浪人 2021-02-07 06:49

Hi there I have json that looks like this:

{
    \"Id\": \" 357342524563456678\",
    \"title\": \"Person\",
    \"language\": \"eng\",
    \"questionAnswer\": [         


        
1条回答
  •  天涯浪人
    2021-02-07 07:38

    So Here is he complete code that gets the keys and values for each item in the object in the array:

    string key = null;
    string value = null;
    
    foreach(var item in inner)
    {
        JProperty questionAnswerDetails = item.First.Value();
    
        var questionAnswerSchemaReference = questionAnswerDetails.Name;
    
        var propertyList = (JObject)item[questionAnswerSchemaReference];
    
        questionDetails = new Dictionary();
    
        foreach (var property in propertyList)
        {
             key = property.Key;
             value = property.Value.ToString();
        }
    
        questionDetails.Add(key, value);               
    }
    

    I can now add key and value to the dictionary

    0 讨论(0)
提交回复
热议问题