Skip to content

Commit

Permalink
Merge pull request #1716 from esdrubal/jsdeserialize
Browse files Browse the repository at this point in the history
[System.Web.Extension] Fixes JavaScriptSerializer.Deserialize.
  • Loading branch information
tritao committed Apr 17, 2015
2 parents 8bbbc63 + 0ac4c24 commit 3fa9d4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Expand Up @@ -495,21 +495,21 @@ bool ParseBuffer (out object result)
break;

case JsonType.TRUE:
if (String.Compare (s, "true", StringComparison.Ordinal) == 0)
if (String.Compare (s.Trim (), "true", StringComparison.Ordinal) == 0)
result = true;
else
converted = false;
break;

case JsonType.FALSE:
if (String.Compare (s, "false", StringComparison.Ordinal) == 0)
if (String.Compare (s.Trim (), "false", StringComparison.Ordinal) == 0)
result = false;
else
converted = false;
break;

case JsonType.NULL:
if (String.Compare (s, "null", StringComparison.Ordinal) != 0)
if (String.Compare (s.Trim (), "null", StringComparison.Ordinal) != 0)
converted = false;
break;

Expand Down
Expand Up @@ -1416,5 +1416,30 @@ public void DeserializeStringWithNewline ()
";
serializer.DeserializeObject (json_with_newline);
}

class Dummy
{
public bool t;
public bool f;
public string s;
public int i;
public double d;
public object o;
}

[Test]
public void DeserializeWhiteSpaces ()
{
string json = "{\"t\" : true , \"f\" : false , \"s\" : \"s\" , \"i\" : 1337 , \"d\" : 1337.0 , \"o\" : null }";

var obj = (new JavaScriptSerializer ()).Deserialize<Dummy>(json);

Assert.IsTrue (obj.t);
Assert.IsFalse (obj.f);
Assert.AreEqual ("s", obj.s);
Assert.AreEqual (1337, obj.i);
Assert.AreEqual (1337.0, obj.d);
Assert.AreEqual (null, obj.o);
}
}
}

0 comments on commit 3fa9d4d

Please sign in to comment.