为什么不从json c#获取ID字段?
我试图使用newtonsoft库从json获取ID,但ID为null,而其他字段(包含内容)是正确的。 课程为:为什么不从json c#获取ID字段?,c#,json,windows-phone,json.net,C#,Json,Windows Phone,Json.net,我试图使用newtonsoft库从json获取ID,但ID为null,而其他字段(包含内容)是正确的。 课程为: public class JsonRequestMapping { private String status; private String count; private String pages; private List<PointOfInterest> posts = new List<PointOfInterest>(
public class JsonRequestMapping
{
private String status;
private String count;
private String pages;
private List<PointOfInterest> posts = new List<PointOfInterest>();
public String Status
{
get { return status; }
set { status = value; }
}
public String Count
{
get { return count; }
set { count = value; }
}
public String Pages
{
get { return pages; }
set { pages = value; }
}
public List<PointOfInterest> Posts
{
get { return posts; }
set { posts = value; }
}
}
public class PointOfInterest
{
private string ID;
private string post_title;
private string post_content;
private string post_modified;
private string featuredimage = null;
private CustomFields custom_fields;
private List<string> localPhotosUrl = new List<string>();
private string latitude = null;
private string longitude = null;
}
当我出现的时候是:身份证不见了
json查看器中的json示例的格式如下
那么,为什么身份证不见了?是c#?的ID表达式问题是
ID
是类的private
字段,没有public
属性。您需要执行以下操作:
public string ID { get; set; }
作为旁注,您可以通过使用保存所有私有字段声明(以及随附的详细信息),其中编译器将为您生成一个支持字段:
public string Status { get; set; }
public string Count { get; set; }
public string Pages { get; set; }
public List<PointOfInterest> Posts { get; set; }
公共字符串状态{get;set;}
公共字符串计数{get;set;}
公共字符串页{get;set;}
公共列表发布{get;set;}
只有当它是属性类型时,才会分配它。
root {1}
array {4}
respond : 1
paging {7}
stillmore : 0
perpage : 150
callpage : 1
next : 2
previous : 0
pages : 1
result : 103
message :
result [103]
0 {26}
ID : 5712
post_title : Fabriano
guid : http:/bla bla bla pe=listing&p=5712
post_content :
public string ID { get; set; }
public string Status { get; set; }
public string Count { get; set; }
public string Pages { get; set; }
public List<PointOfInterest> Posts { get; set; }