且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将此JSON反序列化为对象?

更新时间:2023-01-16 22:59:39

我相信问题出在您的Json字符串中.

I believe the problem is in your Json string.

"Type": [ ... ] 

应该是

"Types": [ ... ]  

Types是应反序列化的属性的名称,您错误地放置Type类名.

Types is the name of property that should be deserialized, you mistakenly put Type the class name instead.

Type类中的Categories属性也是如此.

The same goes for Categories property in the Type class.

,我只是从Json字符串中删除了"MonthlyPerformance"根,它的工作原理就像一个魅力.当然有了Json.NET.

Also I simply removed "MonthlyPerformance" root from the Json string and it worked like a charm. With Json.NET of course.

以下是经过修改的Json的代码片段,具有适当的属性名称(注意,类型,类别,资金和缺少MonthlyPerformance根)

Here is a snippets of the modified Json with appropriate property names (notice, Types, Categories, Funds and the absence of MonthlyPerformance root)

{
    "Types": [ 
    { 
    "id": "65", 
    "countryId": "IE", 
    "name": "Irish Domestic Funds (Gross)", 
    "Categories": [ 
        { 
        "id": "25003334", 
        "countryId": "IE", 
        "name": "UK Equity", 
        "Funds": [ 
            { 
            "id": "25000301", 
            "countryId": "IE", 
            "name": "Aviva Irl UK Equity Fund" 
            }, 
            { 
            "id": "25000349", 
            "countryId": "IE", 
            "name": "New Ireland UK Equity 9" 
        } 
    ] 
}