2

I have this json object that looks like this below but I can't figure out how to acccess the objects data

enter image description here

I want to access the 5th index like this

jsonContent[5] error CS0021: Cannot apply indexing with [] to an expression of type 'object'

4
  • looks like it listing object properties, so maybe try it like "jsonContent.quotes"? Also you have not mentioned if you are trying to deserialize this json into some known type or working with dynamics Commented Nov 21, 2018 at 23:43
  • Your next question will be why quotes is not returning a list of quotes ;) Commented Nov 21, 2018 at 23:47
  • Btw the error means that jsonContent is not an array but it is an object. Commented Nov 21, 2018 at 23:49
  • Which JSON library are you using? If you are using Newtonsoft.JSON, try jsonContent["quotes"]. Commented Nov 21, 2018 at 23:57

2 Answers 2

2

It looks like an object rather than array. So try jsonContent["5"] or jsonContent["[5]"] instead ?

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

Comments

0

Here is what is needed, using the JObject library.

var currency = (jsonContent["quotes"] as JObject)["USD"].Value<decimal>();

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.