0

I have a dictionary with some data and I want to get all the values of each occurrence of specific key name. Is there any predefined method to search for a key in JSON object for all occurrences or need to write user defined method?

Sample data

[{"id":"23","name":"sunny","className":"2","class":{"className":"1","class2":{"className":"3","class":{"className":"4"}}}}]

this is sample data and I want to get all the values with key 'className'

Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
satish kumar V
  • 1,695
  • 6
  • 33
  • 47
  • Yes. Parse the JSON to anonymous object and use reflection to recurisvely traverse the object. There is no "built-in" method to do what you want, afaik. See http://stackoverflow.com/questions/16181298/how-to-do-recursive-descent-of-json-using-json-net to get started. – Erti-Chris Eelmaa Nov 26 '14 at 12:05
  • I am not able to getting your point. Can you give me a small example? @chris Eelmaa – satish kumar V Nov 26 '14 at 12:06
  • Do you HAVE a json object, or just a string? – Ben Robinson Nov 26 '14 at 12:06
  • I think it is not a big deal to convert from string to json object, actually I have string, and I converted it into json object and then to dictionary. If there is possibility with json object only it is much prettier – satish kumar V Nov 26 '14 at 12:07
  • A Dictionary allows only one occurrence of a key. – H H Nov 26 '14 at 13:28

0 Answers0