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

Why doesn't this json parse?

Apr 11, 2012 at 11:44 AM

I have this bit of json:


and after doing:

   Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(MYSTRING);

I get an exception:

Cannot deserialize JSON object into type 'System.String'.


Now, I'm guessing that it's because 'result' is actually an array of information as opposed to a simple string but how do I go about specifying that it's so?

Or am I completely off the mark?


Thanks in advance,



Apr 17, 2012 at 2:47 PM

I've continued investigating thisand as a result have learnt a bit more about JSON.

    "result": {
        "status": 1,
        "output": {
            "user_id": "15452349"
        "errors": []

It seems that this is not an array but an object (with a possible array of errors) and therefore I need a custom JSON converter class.

So, I created a class that subclasses 'JsonConverter' and then another class that is a representation of the JSON above.

However when the program gets to the overriden ReadJson function, it fails at the point of doing:

JObject obj = (JObject)serializer.Deserialize(reader);

Can anybody explain why this might be happening?