在下面找到 json 响应...
{
"personalDetails": {
"Name ": " Taeyeon",
"Date Of Birth ": " 03/09/1989",
"Zodiac ": " Pisces"
},
"education": {
"High School ": " Jeonju Art High school ",
"University ": " -"
}
我的类(class)在这里
public class Biography
{
public personalDetails personalDetails { get; set; }
public education education { get; set; }
public work work { get; set; }
public personal personal { get; set; }
}
public class personalDetails
{
public string Name { get; set; }
public string DateBirth { get; set; }
public string Zodiac { get; set; }
}
public class education
{
public string HighSchool { get; set; }
public string University { get; set; }
}
然后我把代码:
Biography dataSet = JsonConvert.DeserializeObject<Biography>(e.Result);
它不起作用,因为 Arttribute 有空间。 我该怎么办?
最佳答案
尝试添加 JsonProperty
属性。这应该适合你。
[JsonProperty(PropertyName = "Date Of Birth ")]
public string DateBirth { get; set; }
[JsonProperty(PropertyName = "High School ")]
public string HighSchool { get; set; }
编辑
我看到你也有尾随空格,所以更新了上面的属性。对“名称”等做同样的事情。
关于c# - 如何访问名称中有空格的 Json 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16982506/