JsonConvert.DeserializeObject返回null asp.net核心

问题描述

这是对DeserializeObject的调用

var classcateg = JsonConvert.DeserializeObject<CategoryDto>(ResponjsON);

但是我在classcateg中仍然为空

这是我的代码

CategoryDto.cs https://pastebin.com/ktKnvgdK

CategoriesRootObject.cs https://pastebin.com/tpxjp5em

json的响应

{
    "categories": [
        {
            "name": "KIDS","localized_names": [
                {
                    "language_id": 1,"localized_name": "KIDS"
                },{
                    "language_id": 3,{
                    "language_id": 4,{
                    "language_id": 2,"localized_name": "KIDS"
                }
            ],"description": "<p>Get Ahead The List of Our 'Kids Collection'</p>","category_template_id": 1,"Meta_keywords": null,"Meta_description": null,"Meta_title": null,"parent_category_id": 0,"page_size": 6,"page_size_options": "6,3,9","price_ranges": null,"show_on_home_page": null,"include_in_top_menu": true,"has_discounts_applied": null,"published": true,"deleted": false,"display_order": 0,"created_on_utc": "2020-09-17T02:17:25.7941446","updated_on_utc": "2020-09-21T03:03:19.1346274","role_ids": [],"discount_ids": [],"store_ids": [],"image": {
                "src": "https://bateeq-nop-dev.azurewebsites.net/images/thumbs/0002114_kids.jpeg","attachment": null
            },"se_name": "kids","id": 20
        }
    ]
}

有人能帮助我解决这个问题吗?在此之前感谢

解决方法

这是一个有效的文本示例:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

public class Program
{
    public static void Main()
    {
        var jsonString = "{ \"categories\": [ { \"name\": \"KIDS\",\"localized_names\": [ { \"language_id\": 1,\"localized_name\": \"KIDS\" },{ \"language_id\": 3,{ \"language_id\": 4,{ \"language_id\": 2,\"localized_name\": \"KIDS\" } ],\"description\": \"<p>Get Ahead The List of Our 'Kids Collection'</p>\",\"category_template_id\": 1,\"meta_keywords\": null,\"meta_description\": null,\"meta_title\": null,\"parent_category_id\": 0,\"page_size\": 6,\"page_size_options\": \"6,3,9\",\"price_ranges\": null,\"show_on_home_page\": null,\"include_in_top_menu\": true,\"has_discounts_applied\": null,\"published\": true,\"deleted\": false,\"display_order\": 0,\"created_on_utc\": \"2020-09-17T02:17:25.7941446\",\"updated_on_utc\": \"2020-09-21T03:03:19.1346274\",\"role_ids\": [],\"discount_ids\": [],\"store_ids\": [],\"image\": { \"src\": \"https://bateeq-nop-dev.azurewebsites.net/images/thumbs/0002114_kids.jpeg\",\"attachment\": null },\"se_name\": \"kids\",\"id\": 20 } ] }";
        var x = JsonConvert.DeserializeObject<Category>(jsonString);
        
        
        Console.WriteLine(x.Categories.First().Description);
    }
}

public partial class Category
{
    [JsonProperty("categories")]
    public List<CategoryElement> Categories
    {
        get;
        set;
    }
}

public partial class CategoryElement
{
    [JsonProperty("name")]
    public string Name
    {
        get;
        set;
    }

    [JsonProperty("localized_names")]
    public List<LocalizedName> LocalizedNames
    {
        get;
        set;
    }

    [JsonProperty("description")]
    public string Description
    {
        get;
        set;
    }

    [JsonProperty("category_template_id")]
    public long CategoryTemplateId
    {
        get;
        set;
    }

    [JsonProperty("meta_keywords")]
    public object MetaKeywords
    {
        get;
        set;
    }

    [JsonProperty("meta_description")]
    public object MetaDescription
    {
        get;
        set;
    }

    [JsonProperty("meta_title")]
    public object MetaTitle
    {
        get;
        set;
    }

    [JsonProperty("parent_category_id")]
    public long ParentCategoryId
    {
        get;
        set;
    }

    [JsonProperty("page_size")]
    public long PageSize
    {
        get;
        set;
    }

    [JsonProperty("page_size_options")]
    public string PageSizeOptions
    {
        get;
        set;
    }

    [JsonProperty("price_ranges")]
    public object PriceRanges
    {
        get;
        set;
    }

    [JsonProperty("show_on_home_page")]
    public object ShowOnHomePage
    {
        get;
        set;
    }

    [JsonProperty("include_in_top_menu")]
    public bool IncludeInTopMenu
    {
        get;
        set;
    }

    [JsonProperty("has_discounts_applied")]
    public object HasDiscountsApplied
    {
        get;
        set;
    }

    [JsonProperty("published")]
    public bool Published
    {
        get;
        set;
    }

    [JsonProperty("deleted")]
    public bool Deleted
    {
        get;
        set;
    }

    [JsonProperty("display_order")]
    public long DisplayOrder
    {
        get;
        set;
    }

    [JsonProperty("created_on_utc")]
    public string CreatedOnUtc
    {
        get;
        set;
    }

    [JsonProperty("updated_on_utc")]
    public string UpdatedOnUtc
    {
        get;
        set;
    }

    [JsonProperty("role_ids")]
    public List<object> RoleIds
    {
        get;
        set;
    }

    [JsonProperty("discount_ids")]
    public List<object> DiscountIds
    {
        get;
        set;
    }

    [JsonProperty("store_ids")]
    public List<object> StoreIds
    {
        get;
        set;
    }

    [JsonProperty("image")]
    public Image Image
    {
        get;
        set;
    }

    [JsonProperty("se_name")]
    public string SeName
    {
        get;
        set;
    }

    [JsonProperty("id")]
    public long Id
    {
        get;
        set;
    }
}

public partial class Image
{
    [JsonProperty("src")]
    public Uri Src
    {
        get;
        set;
    }

    [JsonProperty("attachment")]
    public object Attachment
    {
        get;
        set;
    }
}

public partial class LocalizedName
{
    [JsonProperty("language_id")]
    public long LanguageId
    {
        get;
        set;
    }

    [JsonProperty("localized_name")]
    public string LocalizedNameLocalizedName
    {
        get;
        set;
    }
}

输出:

<p>Get Ahead The List of Our 'Kids Collection'</p>

https://dotnetfiddle.net/VUqodH