在使用MVC的时候,我们经常用到Newtonsoft.Json来进行实体和JSON 之间的转换,但是有时候,有些实体Newtonsoft.Json转换会出现异常。YeaJur.Mapper正是为了解决这些问题而来,并比Newtonsoft.Json轻量,转换速度快,使用简洁,测试结果如下
PK项 |
YeaJur.Mapper |
Newtonsoft.Json |
||
版本 |
1.0 |
9.0.1 |
||
大小 |
6KB |
514KB |
||
实例(json格式) |
[ { "Products": [ { "Id": "7ef9516e-e019-4b54-9636-89fc56b2906f", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223405)/", "Price": 12.32, "SupplierInfo": { "Id": "00293c28-b29a-4e2c-b5a2-6411d8a67d9e", "Name": "YeaJur.Mapper", "Other": null } }, { "Id": "42f8157a-0f25-472b-9b15-15bc876abeff", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "24e5b9af-5108-462b-924f-b79bf9c1b160", "Name": "YeaJur.Mapper", "Other": null } }, { "Id": "70a3414b-2c76-4417-a47c-4b807301f0f5", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "1990168f-244d-42b8-8276-7ee08e0829a0", "Name": "YeaJur.Mapper", "Other": null } } ], "SellerInfo": { "Id": "31875b3f-970d-4383-9d2f-b769c3e7cc87", "Name": "YeaJur.Mapper", "Remark": "YeaJur.Mapper" } }, { "Products": [ { "Id": "cd78b31d-0e83-4586-a202-f45349eabe98", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "e4ade655-22e3-4850-96dc-02f7059479b8", "Name": "YeaJur.Mapper", "Other": null } }, { "Id": "20d2219b-d520-4c58-840e-c11b10e8878f", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "3817b018-369a-4413-b0df-cde5a877d0d7", "Name": "YeaJur.Mapper", "Other": null } }, { "Id": "b83d5db6-1216-4a56-a448-d5c478a30b32", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "321b2dad-7d66-42d0-b75d-c019cd297a1b", "Name": "YeaJur.Mapper", "Other": null } } ], "SellerInfo": { "Id": "c7e7f104-3484-4640-9003-ad6ddd5cb3dc", "Name": "YeaJur.Mapper", "Remark": "YeaJur.Mapper" } }, { "Products": [ { "Id": "1d8c2158-008c-4ad1-8803-915a5e32c695", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "58c89199-c1fc-4c94-8d74-3ee3db5f074b", "Name": "YeaJur.Mapper", "Other": null } }, { "Id": "311ca89e-be6c-4bcf-8730-12abb1388319", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "87f3c2ce-d6bd-4cfb-bcf0-9a48615b223c", "Name": "YeaJur.Mapper", "Other": null } }, { "Id": "5d23505c-206a-4bdc-9086-92532fcf37d7", "Name": "YeaJur.Mapper", "Count": 32, "CreateTime": "/Date(1484796223406)/", "Price": 12.32, "SupplierInfo": { "Id": "e5582774-ca39-43e0-8e78-9511ea96061b", "Name": "YeaJur.Mapper", "Other": null } } ], "SellerInfo": { "Id": "9f1b4e00-bf00-4946-8e8a-a2780c118079", "Name": "YeaJur.Mapper", "Remark": "YeaJur.Mapper" } } ] |
|||
实体转JSON——写法 |
var json = model.ToJson(); |
var json = JsonConvert.SerializeObject(model); |
||
实体转JSON——运行结果样例 |
|
|||
实体转JSON——运行平均速度 |
9.4ms(包括创建实体时间) |
151.8ms(包括创建实体时间) |
||
JSON转实体——写法 |
var model = json.ToModel<List<Order>>(); |
var model = JsonConvert.DeserializeObject<List<Order>>(json); |
||
JSON转实体——运行结果样例 |
|
|||
JSON转实体——运行平均速度 |
15.2ms |
167.8ms |
在项目的nuget中搜索 Yeajur.Mapper 即可下载使用
https://www.nuget.org/packages/YeaJur.Mapper