C# Newtonsoft JSON.NET反序列化为类型化对象
我想使用JSon.net来反序列化flickr.com photoset(请参阅) 我得到的JSON的一个例子是C# Newtonsoft JSON.NET反序列化为类型化对象,c#,json,json.net,flickr,C#,Json,Json.net,Flickr,我想使用JSon.net来反序列化flickr.com photoset(请参阅) 我得到的JSON的一个例子是 { photoset: { id: "72154517991528243", primary: "6346929005", owner: "9999999@N00", ownername: "myname", photo: [ { id: "6340104934", secret: "18ab51078a", server: "6106", farm: 7, title: "
{
photoset: {
id: "72154517991528243",
primary: "6346929005",
owner: "9999999@N00",
ownername: "myname",
photo: [
{
id: "6340104934",
secret: "18ab51078a",
server: "6106",
farm: 7,
title: "Day #1/30 - homemade kanelbullar",
isprimary: "0"
}
.... lots of these photos...
],
page: 1,
per_page: 500,
perpage: 500,
pages: 1,
total: "18"
},
stat: "ok"
}
我使用的类有:
class FlickrSet
{
Photoset photoset {get;set;}
string stat{get;set;}
}
class Photoset
{
public string id { get; set; }
public string primary { get; set; }
public string owner { get; set; }
public string ownername { get; set; }
public List<Photo> photo { get; set; }
public int page { get; set; }
public int per_page { get; set; }
public int perpage { get; set; }
public int pages { get; set; }
public string total { get; set; }
}
class Photo
{
public string id { get; set; }
public string secret { get; set; }
public string server { get; set; }
public int farm { get; set; }
public string title { get; set; }
public string isprimary { get; set; }
}
class-FlickrSet
{
Photoset Photoset{get;set;}
字符串stat{get;set;}
}
类照片集
{
公共字符串id{get;set;}
公共字符串主{get;set;}
公共字符串所有者{get;set;}
公共字符串所有者名称{get;set;}
公共列表照片{get;set;}
公共整型页{get;set;}
每_页公共整数{get;set;}
公共整型每页{get;set;}
公共整型页{get;set;}
公共字符串总计{get;set;}
}
班级照片
{
公共字符串id{get;set;}
公共字符串机密{get;set;}
公共字符串服务器{get;set;}
公共int场{get;set;}
公共字符串标题{get;set;}
公共字符串isprimary{get;set;}
}
当我使用它们进行反序列化时:
var s= JsonConvert.DeserializeObject<FlickrSet>(outPut );
var s=JsonConvert.DeserializeObject(输出);
s
的两个成员都为空
我试图匹配字符串、整数和列表,但可能出现了一些错误。
谢谢大家 System.Web.Script.Serialization.JavaScriptSerializer js=new System.Web.Script.Serialization.JavaScriptSerializer();
System.Web.Script.Serialization.JavaScriptSerializer js = new system.Web.Script.Serialization.JavaScriptSerializer();
return js.Deserialize<FlickrSet>(value);
返回js.Deserialize(值);
有两个错误:flickrset上的属性不是公共的,照片是数组而不是列表(不知道为什么)
类FlickrSet
{
砰的一声!!相反.Net应该表现得像一个智能机器人:)
**public** Photoset photoset {get;set;}
**public** string stat{get;set;}
}
class Photoset
{
public string id { get; set; }
public string primary { get; set; }
public string owner { get; set; }
public string ownername { get; set; }
public **Photo[]** photo { get; set; }
public int page { get; set; }
public int per_page { get; set; }
public int perpage { get; set; }
public int pages { get; set; }
public string total { get; set; }
}
class Photo
{
public string id { get; set; }
public string secret { get; set; }
public string server { get; set; }
public int farm { get; set; }
public string title { get; set; }
public string isprimary { get; set; }
}