Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using Json.NET 6.x and I noticed weird behaviour:

If I want to deserialize this simple JSON, I get an error:

The code to deserialize:

 object o = Newtonsoft.Json.JsonConvert.DeserializeObject(text);

and the JSON:

[
  {
    "Username": "tb386",
    "TimestampUpdated": "2015-01-19T18:49:52.771571+01:00",
    "AuthTokens": [
        "Ua7JR5E7hSAxjafp6dpMrvw3HlICW3ZZdDuArMaU5ks="
      ]
  }
]

The error I get is:

Unexpected character encountered while parsing value: U. Path '', line 0, position 0.

If I remove the array, it works fine. But all I have to do, is to remove the string inside the array, making it empty:

[
  {
    "Username": "tb386",
    "TimestampUpdated": "2015-01-19T18:49:52.771571+01:00",
    "AuthTokens": [ ]
  }
]

and then it works fine. I should also note that the serialized JSON was produced by the Newtonsoft library, so the source is the same library!

If I try a validator (like http://jsonlint.com/) on the JSON with the array, it valides OK!

Can anyone help me out here?

Additional information: Even if I add a string inside VS and write the JSON hardcoded, it fails!

string text =  "[ {\"Username\": \"tb386\",\"TimestampUpdated\": \"2015-01-19T18:49:52.771571+01:00\",\"AuthTokens\": [\"Ua7JR5E7hSAxjafp6dpMrvw3HlICW3ZZdDuArMaU5ks=\"] } ]";
  
object o = Newtonsoft.Json.JsonConvert.DeserializeObject(text);

Version info on Newtonsoft dll:

enter image description here

share|improve this question
3  
Show some relevant stuff instead: what does the model to which you're deserializing look like? –  Jeroen Vannevel Jan 20 at 15:23
3  
That is completely irrelevant. I am deserializing to "object", so forget the model. This is as basic as it gets. –  Ted Jan 20 at 15:28
    
Seems to work fine in linqpad? –  James Thorpe Jan 20 at 15:37
    
yes, it all works in all validators I have tried =) I also mentioned that above. The strange thing is that Newtonsoft does not allow it, giving me the error as mentioned above. –  Ted Jan 20 at 15:38
1  
What's the exact version number for Json.NET that produces the error? –  Steven Liekens Jan 20 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.