gpt4 book ai didi

c# - 生成 json 时类型无效?

转载 作者:行者123 更新时间:2023-11-30 20:28:58 25 4
gpt4 key购买 nike

我有这个 json:

{
"page": "36",
"bookmaker_urls": {
"13": [{
"link": "http://www.bet365.com/home/?affiliate=365_179024",
"name": "Bet 365"
}]
},
"block_service_id": "competition_summary_block_competitionmatchessummary",
"round_id": "36003",
"outgroup": "",
"view": "1",
"competition_id": "13"
}

我已将其插入此工具:http://json2csharp.com/

这将返回:

 public class __invalid_type__13
{
public string link { get; set; }
public string name { get; set; }
}

public class BookmakerUrls
{
public List<__invalid_type__13> __invalid_name__13 { get; set; }
}

public class RootObject
{
public int page { get; set; }
public BookmakerUrls bookmaker_urls { get; set; }
public string block_service_id { get; set; }
public int round_id { get; set; }
public bool outgroup { get; set; }
public int view { get; set; }
public int competition_id { get; set; }
}

为什么类型无效?

最佳答案

13 不是 .NET 中的有效属性名称,您使用的工具似乎试图将每个 JSON 属性映射到 .NET 类属性。

您可能希望 bookmaker_urls 成为字典:

public class BookmakerUrl
{
public string link { get; set; }
public string name { get; set; }
}

public class RootObject
{
public int page { get; set; }
public Dictionary<string, List<BookmakerUrl>> bookmaker_urls { get; set; }
public string block_service_id { get; set; }
public int round_id { get; set; }
public bool outgroup { get; set; }
public int view { get; set; }
public int competition_id { get; set; }
}

关于c# - 生成 json 时类型无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46735170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com