LitJSON / litjson

JSON library for the .Net framework
https://litjson.net/
Other
1.37k stars 404 forks source link

Please support RFC 7159 #43

Open ganaware opened 9 years ago

ganaware commented 9 years ago

The current LitJSON is based on RFC 4627 obsoleted by RFC 7159 ( https://tools.ietf.org/html/rfc7159 ). There are many changes between them.

The trouble I felled into is that:

var result = LitJson.JsonMapper.ToObject<string>("\"foo\"");

throws an exception.

In Appendix A of RFC 7159:

So, the result should be "foo" with no exception.

The following patch can fix the above problem:

--- JsonReader.cs.orig  2015-07-02 18:29:53.554902400 +0900
+++ JsonReader.cs   2015-07-02 18:23:18.075301700 +0900
@@ -215,10 +215,20 @@
                          '"');

             TableAddRow (ParserToken.Text);
+            TableAddCol (ParserToken.Text, '"',
+                         (int) ParserToken.String);
             TableAddCol (ParserToken.Text, '[',
                          (int) ParserToken.Array);
             TableAddCol (ParserToken.Text, '{',
                          (int) ParserToken.Object);
+            TableAddCol (ParserToken.Text, (int) ParserToken.Number,
+                         (int) ParserToken.Number);
+            TableAddCol (ParserToken.Text, (int) ParserToken.True,
+                         (int) ParserToken.True);
+            TableAddCol (ParserToken.Text, (int) ParserToken.False,
+                         (int) ParserToken.False);
+            TableAddCol (ParserToken.Text, (int) ParserToken.Null,
+                         (int) ParserToken.Null);

             TableAddRow (ParserToken.Value);
             TableAddCol (ParserToken.Value, '"',