-3

i have a json in below format

  {{
      "encoding_version": 1,
      "root": {
        "_type": "dictionary",  
        "test1": 0,
        "test2": 6593,
        "test3": ".key.test",
        "test4": "key.test",
        "test5": ".key.14",     
        "test6": 6159
      }
    }}

i am trying to get "test5" value which is 14

var data = (JObject)JsonConvert.DeserializeObject(inputJson);
var id = data["test5"];
            
            

however getting it null,Please help.

4

1 Answer 1

0

You have provide JSON with two times curl braces, i have made this small correction in your input JSON :

{
  "encoding_version": 1,
  "root": {
  "_type": "dictionary",
  "test1": 0,
  "test2": 6593,
  "test3": ".key.test",
  "test4": "key.test",
  "test5": ".key.14",
  "test6": 6159
  }
}

As your deserialization is correct and you are looking for value of "test5" which is ".key.14". Your desired key is two level down in JSON i.e. first go for "root" and then "test5". Hence your code will look like:

string test5Value = (string)result["root"]["test5"]; 

output => .key.14

If you want 14 then you might need to split output string and take out the required value.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.