From: Miguel de Icaza Date: Thu, 29 Dec 2011 14:10:14 +0000 (-0500) Subject: Allow trailing commas on Json objects X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=37b85d86ac82367f3c347e7dd9364e9adc4621be;p=mono.git Allow trailing commas on Json objects --- diff --git a/mcs/class/System.Json/System.Json_test.dll.sources b/mcs/class/System.Json/System.Json_test.dll.sources new file mode 100644 index 00000000000..8d6ae225c73 --- /dev/null +++ b/mcs/class/System.Json/System.Json_test.dll.sources @@ -0,0 +1 @@ +System.Json/JsonValueTest.cs \ No newline at end of file diff --git a/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs b/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs new file mode 100644 index 00000000000..754f8556a5f --- /dev/null +++ b/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs @@ -0,0 +1,29 @@ +// +// JsonValueTest.cs: Tests for JSonValue +// +// Copyright 2011 Xamarin, Inc. +// +// Authors: +// Miguel de Icaza +// +using NUnit.Framework; +using System; +using System.IO; +using System.Text; +using System.Json; + +namespace MonoTests.System +{ + [TestFixture] + public class JsonValueTests { + // Tests that a trailing comma is allowed in dictionary definitions + [Test] + public void LoadWithTrailingComma () + { + var j = JsonValue.Load (new StringReader ("{ \"a\": \"b\",}")); + Assert.AreEqual (1, j.Count, "itemcount"); + Assert.AreEqual (JsonType.String, j ["a"].JsonType, "type"); + Assert.AreEqual ("b", (string) j ["a"], "value"); + } + } +} diff --git a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JavaScriptReader.cs b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JavaScriptReader.cs index 0a2de0c8d9a..84016a99028 100644 --- a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JavaScriptReader.cs +++ b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JavaScriptReader.cs @@ -68,6 +68,8 @@ namespace System.Runtime.Serialization.Json } while (true) { SkipSpaces (); + if (PeekChar () == '}') + break; string name = ReadStringLiteral (); SkipSpaces (); Expect (':');