mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
479 stars 147 forks source link

ToObject error #105

Closed MetSystem closed 5 years ago

MetSystem commented 5 years ago
 string json = "{id:'1',name:'123'}";
            var type = Type.GetType("WebApi.Test", true, true);
            var data2 = fastJSON.JSON.ToObject(json, type);

namespace WebApi
{
    public class Test
    {
        public string id { get; set; }
        public string name { get; set; }
    }
}
mgholam commented 5 years ago

1) The json standard requires double quotes so add ...3'}".Replace("'","\"); 2) The json standard also requires double quotes around the property names, you can however overcome this by setting fastJSON.JSON.Parameters.AllowNonQuotedKeys = true; globally or on a call basis.