0

How can I access the value of url in the JSON string below?

JSON

{
    "id": "7453",
    "picture": {
        "data": {
            "is_silhouette": false,
            "url": "https:\/\/scontent.xx.fbcdn.net\/v\/t1.0-1\/p50x50\/gf6474hfff.jpg?oh=fy&oe=trtr"
        }
    }
}

Dim o As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(json)

I can access id like so:

o("id").ToString()

So I would expect the following would work for the url property, but I get an error:

Object reference not set to an instance of an object

o("picture.data.url").ToString()
2
  • 5
    o("picture")("data")("url") - it wont parse the string obj reference for you. its usually easier to work with when deserialized Commented May 2, 2017 at 15:26
  • 1
    it is also easier to see the hierarchy if you paste it into something like jsonlint.com Commented May 2, 2017 at 15:32

1 Answer 1

1

You could do it one at a time.

Dim pic = o("picture")("data")("url")

I also found out that you can also do another method in Newtonsoft.Json:

Dim pic = o.SelectToken("picture.data.url")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.