在 ASP.NET 核心网站 api 中读取 JSON 值
read JSON value in ASP.NET Core web api
从中获取价值的最佳方法是什么:
{"profileObj":{"Name":"xxx","FirstName":"xxx","FastName":"xxx","Email":"xxx"}}
尝试使用 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; }
}
从中获取价值的最佳方法是什么:
{"profileObj":{"Name":"xxx","FirstName":"xxx","FastName":"xxx","Email":"xxx"}}
尝试使用 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; }
}