我有一个JSON字符串,需要反序列化为一个对象.
这是我尝试过的:
课程:
public class trn
{
public string visited_date { get; set; }
public string party_code { get; set; }
public string response { get; set; }
public string response_type { get; set; }
public string time_stamp { get; set; }
public string trans_id { get; set; }
public double total_amount { get; set; }
public double discount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
json字符串:
string json = "{\"trn\":{\"visited_date\":\"2015-04-05\",\"party_code\":\"8978a1bf-c88b-11e4-a815-00ff2dce0943\",\"response\":\"Reason 5\",\"response_type\":\"NoOrder\",\"time_stamp\":\"2015-04-05 18:27:42\",\"trans_id\":\"8e15f00b288a701e60a08f968a42a560\",\"total_amount\":0.0,\"discount\":0.0}}";
trn model2 = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<trn>(json);
Run Code Online (Sandbox Code Playgroud)
并使用json.net
trn model = …Run Code Online (Sandbox Code Playgroud) 我有c#对象,我需要在javascript中引用默认填充.目前我正在维护两个不可维护的不同对象.
例如(为演示目的而简化):
C#
public class Text
{
public string Name {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
JSON
{
'text': {
name: undefined
}
}
Run Code Online (Sandbox Code Playgroud)
我知道有很多方法可以实现这一目标,但想知道是否有人有推荐的解决方案.谢谢!
public async Task<WalletTrans> getCredits(int id)
{
var credit = await _context.walletTrans.ToAsyncEnumerable().Where(r => r.Id == id).Sum(s => s.quantity);
return credit;
}
Run Code Online (Sandbox Code Playgroud)
我上面的代码使用的是C#.net核心,据说可以返回表中字段的总和.
但我有这个错误.
"无法将类型'decimal'隐式转换为'ProjectName.Models.ModelName'[ProjectName]"
我有一个数据样本,如下所示.
{
"ditems": [
{
"type": "ditem",
"name": "webmet.com",
"ditem": 0,
"links": [
"www.abc.com/a",
"www.sempo.org/"
]
},
{
"type": "ditem",
"name": "webmet.com/who-we-are/careers",
"ditem": 2,
"links": [
"http://www.tele12.com/about",
"http://tele12.com/life-at-teletech-en-US/about-teletech/"
]
}
],
"themes": [
{
"type": "theme",
"name": "http://searchm.com/isr/agenda",
"description": "",
"slug": "http://searchm.com/isr/agenda-2"
},
{
"type": "theme",
"name": "http://www.sempo.org/",
"description": "",
"slug": "http://www.sempo.org/-2"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码
var InternalURLList = dtInternalURL.AsEnumerable().Select(c => c.Field<string>("URL")).Distinct().ToList();
StringBuilder sb = new StringBuilder();
StringBuilder ThemeSb = new StringBuilder();
sb.Append("{\"ditems\":[");
if (InternalURLList.Count > 0)
{
for (int …Run Code Online (Sandbox Code Playgroud)