F.Rocco
F.Rocco

Reputation: 21

C# Get JObject inner token

I have this Json structure:

{
  "rc": 1,
  "msg": 
  [
    {
      "msgId": "6661",
      "msgTxt": "Invalid Token"
    }
  ]
}

How can I get the 6661 Value? I've tried lots of paths, but it seems those two square brackets are making my day hard

Thanks

Upvotes: 0

Views: 202

Answers (2)

GGO
GGO

Reputation: 2748

Using JObject parser, you could use :

var obj = JObject.Parse(yourObjectJson);
var value = obj["msg"][0]["msgId"];

Upvotes: 0

Richard
Richard

Reputation: 108975

Assuming jdoc is your parsed document, then:

var res = jdoc["msg"][0]["msgId"];

should do it (but real code should handle errors as well).

Upvotes: 1

Related Questions