我正在尝试反序列化提供的Json,但是当下载工作且反序列化没有抛出任何错误时,结果对象是RootObjectSingle只保存一个空值RootObject。任何人都可以看到我做错了什么来防止数据级联到正确的类?
Desirialser COde:
List ImportHolder = new List();
string JsonControlString = "S";
;
foreach (string Json1 in JsonList)
{
string Json2 = Json1;
JsonControlString = UnpackJson<string>(Json2);
JsonControl = JsonConvert.DeserializeObject<RootObjectSingle>(JsonControlString);
...}
我有一组将结构定义为
的类public class List
{
[JsonProperty]
public string feed { get; set; }
[JsonProperty]
public string product_device { get; set; }
[JsonProperty]
public string unified_product_name { get; set; }
[JsonProperty]
public int? product_franchise_id { get; set; }
[JsonProperty]
public string product_category { get; set; }
[JsonProperty]
public int rank { get; set; }
[JsonProperty]
public object parent_company_id { get; set; }
[JsonProperty]
public string publisher_name { get; set; }
[JsonProperty]
public string category { get; set; }
[JsonProperty]
public object company_id { get; set; }
[JsonProperty]
public string product_franchise_name { get; set; }
[JsonProperty]
public string company_name { get; set; }
[JsonProperty]
public bool has_iap { get; set; }
[JsonProperty]
public object publisher_id { get; set; }
[JsonProperty]
public string product_name { get; set; }
[JsonProperty]
public double price { get; set; }
[JsonProperty]
public int estimate { get; set; }
[JsonProperty]
public string product_id { get; set; }
[JsonProperty]
public string country { get; set; }
[JsonProperty]
public string release_date { get; set; }
[JsonProperty]
public string parent_company_name { get; set; }
[JsonProperty]
public object unified_product_id { get; set; }
}
public class listloop : IEnumerator<List>, IEnumerable<List>
{
[JsonProperty]
public List<List> list { get; set; }
int position = -1;
public List Current
{
get { return list.ToArray()[position]; }
}
public void Dispose()
{
throw new NotImplementedException();
}
object System.Collections.IEnumerator.Current
{
get { return list.ToArray()[position]; }
}
public bool MoveNext()
{
position++;
return (position < list.Count);
}
public void Reset()
{
position = 0;
}
public IEnumerator<List> GetEnumerator()
{
return ((IEnumerable<List>)this.list).GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return ((System.Collections.IEnumerable)this.list).GetEnumerator();
}
}
public class RootObject : IEnumerator<listloop>, IEnumerable<listloop>
{
[JsonProperty]
public int code { get; set; }
[JsonProperty]
public string end_date { get; set; }
[JsonProperty]
public string vertical { get; set; }
[JsonProperty]
public string granularity { get; set; }
[JsonProperty]
public string device { get; set; }
[JsonProperty(PropertyName="list")]
public List<listloop> listloop { get; set; }
[JsonProperty]
public string start_date { get; set; }
[JsonProperty]
public string market { get; set; }
private int position = -1;
public List Current
{
get { return listloop.ToArray()[position].Current; }
}
public void Dispose()
{
throw new NotImplementedException();
}
object System.Collections.IEnumerator.Current
{
get { return listloop.ToArray()[position]; }
}
public bool MoveNext()
{
position++;
return (position < listloop.Count);
}
public void Reset()
{
position = 0;
}
public IEnumerator<listloop> GetEnumerator()
{
return ((IEnumerable<listloop>)this.listloop).GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return ((System.Collections.IEnumerable)this.listloop).GetEnumerator();
}
listloop IEnumerator<listloop>.Current
{
get { return listloop.ToArray()[position]; }
}
}
public class RootObjectSingle
{
[JsonProperty]
public RootObject rootobject { get; set; }
}
我正在尝试反序列化提供的JSON数据流。 反序列化命令似乎有效但当我来处理结果时,“根对象”对象为空。
以下示例JSON(我尽可能多地提供,不是整个文件)
{"code": 000, "end_date": "0000-00-00", "vertical": "apps", "granularity": "daily", "device": "android", "list": [{"feed": "free", "product_device": "Android", "unified_product_name": "Pou", "product_franchise_id": null, "product_category": "Casual", "rank": 0, "parent_company_id": 0000000000000000, "publisher_name": "Zakeh", "category": "OVERALL > GAME", "company_id": 0000000000000000, "product_franchise_name": "Pou", "company_name": "Zakeh", "has_iap": true, "publisher_id": 00000000000000, "product_name": "Pou", "price": 0.0, "estimate": 00000, "product_id": "me.pou.app", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "Zakeh", "unified_product_id": 0000000000000000}, {"feed": "free", "product_device": "Android", "unified_product_name": "Clumsy Bird", "product_franchise_id": null, "product_category": "Game Action", "rank": 0, "parent_company_id": 0000000000000000, "publisher_name": "Candy Mobile", "category": "OVERALL > GAME", "company_id": 0000000000000000, "product_franchise_name": "Clumsy Bird", "company_name": "Candy Mobile", "has_iap": true, "publisher_id": 00000000000000, "product_name": "Clumsy Bird", "price": 0.0, "estimate": 00000, "product_id": "com.seriouscorp.clumsybird", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "Candy Mobile", "unified_product_id": 0000000000000000}, {"feed": "free", "product_device": "Android", "unified_product_name": "Subway Surfers", "product_franchise_id": null, "product_category": "Game Arcade", "rank": 0, "parent_company_id": 0000000000000000, "publisher_name": "Kiloo", "category": "OVERALL > GAME", "company_id": 0000000000000000, "product_franchise_name": "Subway Surfers", "company_name": "Kiloo", "has_iap": true, "publisher_id": 00000000000000, "product_name": "Subway Surfers", "price": 0.0, "estimate": 00000, "product_id": "com.kiloo.subwaysurf", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "Kiloo", "unified_product_id": 0000000000000000}, {"feed": "free", "product_device": "Android", "unified_product_name": "My Talking Tom", "product_franchise_id": 00, "product_category": "Casual", "rank": 0, "parent_company_id": 0000000000000000, "publisher_name": "Outfit0", "category": "OVERALL > GAME", "company_id": 0000000000000000, "product_franchise_name": "Talking...", "company_name": "Outfit 0", "has_iap": true, "publisher_id": 00000000000000, "product_name": "My Talking Tom", "price": 0.0, "estimate": 00000, "product_id": "com.outfit0.mytalkingtomfree", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "Outfit 0", "unified_product_id": 0000000000000000}, {"feed": "free", "product_device": "Android", "unified_product_name": "Show do Milh\u00e0o", "product_franchise_id": null, "product_category": "Casual", "rank": 0, "parent_company_id": null, "publisher_name": "LGR Mobile Apps", "category": "OVERALL > GAME", "company_id": null, "product_franchise_name": "Show do Milh\u00e0o", "company_name": "LGR Mobile Apps", "has_iap": false, "publisher_id": 00000000000000, "product_name": "Show do Milh\u00e0o 0000", "price": 0.0, "estimate": 00000, "product_id": "br.com.lgrmobile.sdm", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "LGR Mobile Apps", "unified_product_id": 0000000000000000}, {"feed": "free", "product_device": "Android", "unified_product_name": "Candy Crush Saga", "product_franchise_id": null, "product_category": "Casual", "rank": 0, "parent_company_id": 0000000000000000, "publisher_name": "King.com", "category": "OVERALL > GAME", "company_id": 0000000000000000, "product_franchise_name": "Candy Crush Saga", "company_name": "King", "has_iap": true, "publisher_id": 00000000000000, "product_name": "Candy Crush Saga", "price": 0.0, "estimate": 00000, "product_id": "com.king.candycrushsaga", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "King", "unified_product_id": 0000000000000000}, {"feed": "free", "product_device": "Android", "unified_product_name": "Zombie Tsunami", "product_franchise_id": null, "product_category": "Game Arcade", "rank": 0, "parent_company_id": 0000000000000000, "publisher_name": "Mobigame S.A.R.L.", "category": "OVERALL > GAME", "company_id": 0000000000000000, "product_franchise_name": "Zombie Tsunami", "company_name": "MobiGame.net", "has_iap": true, "publisher_id": 00000000000000, "product_name": "Zombie Tsunami", "price": 0.0, "estimate": 00000, "product_id": "net.mobigame.zombietsunami", "country": "BR", "release_date": "0000-00-00", "parent_company_name": "MobiGame.net", "unified_product_id": 0000000000000000},