HttpWebRequest request = WebRequest.Create("https:...") as HttpWebRequest;
var response = request.GetResponse() as HttpWebResponse;
var reader = new StreamReader(response.GetResponseStream());
var lines = reader.ReadToEnd();
现在行回来了
{"用户名":"我""两性":雄性}
我希望将其自动映射到我已经设置的模型类
public class Person
{
public string username { get; set; }
public string gender { get; set; }
}
知道如何解决这个问题吗?
答案 0 :(得分:1)
您可以使用Newtonsoft.Json
执行此任务。只需将Newtonsof.Json包添加到您的项目中,然后执行:
var person = JsonConvert.Deserialize<Person>(lines);