This project has moved. For the latest updates, please go here.

Basics of JsonTextReader

May 1, 2010 at 11:28 AM

I'm really struggling with what I think is a basic function of this component.  I'm reading some facebook data into a string and have created a JsonTextReader.  I want to be able to get to the data inside the string that is in JSON format.


I can use .read to iterate through the data - and I know its full of data as it iterates the correct number of times, however I can't figure out how to just get the data out cleanly.  As an example there is a element in the data called "name" which oddly enough holds a name, like "John Smith".  I'm expecting to be able to iterate through the data using one read after another and then evaluate some property to be able to see if it's the "name" element.

But... I just can't see what 'thing' i'm supposed to evalauate to see this data.  Can anyone help?

There is a.value propert - however the data in that element is complex and contains descriptors and property names and the actual data all in a big ugly string.  Any ideas?  Surely this is the easy part, right?


May 1, 2010 at 12:56 PM

TokenType and Value will hold information about the current point in the JSON. If it is one string containing JSON then you have incorrectly escaped JSON. See for how JSON should be formatted.

May 3, 2010 at 12:33 AM

OK - I think I get it.  What I was expecting appears not to be the case.

Every .read moves one step through the JSON - so if I have a pair that is "id";"12345" then this takes 2 reads, right?

So am I best to then load all this stuff into a dictionary or something to be able to reference it a little easier?

My expectations was to be able to do something where I reference the property name in the pair and get the value back.  Is that possible?

Thanks for your help.