【发布时间】:2021-11-12 23:17:48
【问题描述】:
获取价值的最佳方法是:
{"profileObj":{"Name":"xxx","FirstName":"xxx","FastName":"xxx","Email":"xxx"}}
【问题讨论】:
标签: c# json asp.net-core .net-core asp.net-web-api
获取价值的最佳方法是:
{"profileObj":{"Name":"xxx","FirstName":"xxx","FastName":"xxx","Email":"xxx"}}
【问题讨论】:
标签: c# json asp.net-core .net-core asp.net-web-api
使用 System.Text.Json 试试这个
//your json
var json= "{\"profileObj\":{\"Name\":\"xxx\",\"FirstName\":\"xxx\",\"FastName\":\"xxx\",\"Email\":\"xxx\"}}";
using System.Text.Json;
.....
var jD= JsonSerializer.Deserialize<Root>(json);
var value =jD.profileObj;
var name= value.Name;
或者您可以安装 Newtonsoft.Json nuget 包并使用此代码
using Newtonsoft.Json;
.....
var jD = JsonConvert.DeserializeObject<Root>(json);
......
类
public class ProfileObj
{
public string Name { get; set; }
public string FirstName { get; set; }
public string FastName { get; set; }
public string Email { get; set; }
}
public class Root
{
public ProfileObj profileObj { get; set; }
}
【讨论】: