将 ExpandoObject 转换为类型,什么更有效,更省时,做那个客户端或服务器端

本文关键字:服务器端 客户端 更省 有效 转换 ExpandoObject 类型 什么 | 更新日期: 2023-09-27 18:35:08

问题定义:

我有一个 ExpandoObject,我需要将其转换为"客户"类型等类型,问题在于没有实现这一目标,我想知道我应该使用 javascript 接近服务器端还是客户端,我可以两种方式实现我想要的,但哪个更有效且耗时更少?

服务器端方法:

public IEnumerable<T> Convert<T>(dynamic self)
{
    List<T> model = new List<T>();
    var jsSerializer = new JavaScriptSerializer();
    foreach (var obj in self)
    {
        model.Add(jsSerializer.ConvertToType<T>(obj));
    }
    return model.AsEnumerable();
}

客户端方法:

var model = [];
data.forEach(function (item) {
    var property = [];
    item.forEach(function (pair) {
        property[pair.Key] = pair.Value;
    });
    model.push(property);
});

二手ORM:罗伯·科纳里的巨著

原始响应(无转换):

[[{ "Key": "ID", "Value": 2 }, { "Key": "customerID", "Value": 1 }, { "Key": "orderID", "Value": 1 }, { "Key": "address", "value": "25 Ibrahim Nagy Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1381528800000)/" }, { "Key": "deliveryPersonnelID", "Value": 1 }], [{ "Key": "ID", "Value": 3 }, { "Key": "customerID", "Value": 2 }, { "Key": "orderID", "Value": 2 }, { "Key": "address", "value": "

14 Ibrahim Nagy Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1386972000000)/" }, { "Key": "deliveryPersonnelID", "Value": 2 }], [{ "Key": "ID", "Value": 4 }, { "Key": "customerID", "Value": 1 }, { "Key": "orderID", "Value": 3 }, { "Key": "address", "value": "30 Abbas Akad Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1387922400000)/" }, { "Key": "deliveryPersonnelID", "Value": 2 }], [{ "Key": "ID", "Value": 5 }, { "Key": "customerID", "Value": 3 }, { "Key": "orderID", "Value": 4 }, { "Key": "address", "Value": "25 Hassan Maamoon Street, NasrCity, Cairo

" }, { "Key": "deliveryDateTime", "Value": "/Date(1388354400000)/" }, { "Key": "deliveryPersonnelID", "Value": 3 }]]

将 ExpandoObject 转换为类型,什么更有效,更省时,做那个客户端或服务器端

我决定做转换客户端,我不知道这对我来说是正确的,我的意思是让客户端做一些工作,而且它也不是一件艰苦的工作,所以为什么要浪费时间服务器端呢?