DataContractJsonSerializer:令牌'null'是预期的,但发现'new '



当我尝试将JSON反序列化为对象时收到此错误。

Additional information: 
There was an error deserializing the object of type uwpPlatenInformationScreen.Models.RootObject. The token 'null' was expected but found 'new '.

找不到任何解决方案,我将其设置为 UTF8,并且我有一个正确的 JSON 模型。

我的根对象没有错,所以我不知道该考虑什么了。

功能:

public static async Task<RootObject> GetTodaysLunch(ObservableCollection<RootObject> menu )
{
    string jsonMessage = await GetJsonDataFromMashie();
    //deserialize json data into object
    var serializer = new DataContractJsonSerializer(typeof (RootObject));
    var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonMessage));
    RootObject result = (RootObject) serializer.ReadObject(ms);
    return result;
}

JSON 字符串(API 格式不佳):

{
"Weeks": [{
    "MenuId": "af77367d-9159-459d-863a-a23b00b6c7f8",
    "MenuName": "Skolmatsedel",
    "WeekNumber": 4,
    "Days": [{
        "InfoText": null,
        "DayMenuDate": new Date(1453676400000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Köttfärssås med pasta",
            "MealId": "d09c0ccc-d491-4007-8ba9-3a47c83550ac",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Medelhavsgryta med quinoa",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Rotfruktsgratäng med fetaostcremé och sautegrönsaker",
            "MealId": "664a1858-78b3-467c-8167-53eb511f9117",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1453762800000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Pytt i panna med rödbetor",
            "MealId": "359d7926-aefa-4a8d-94ff-9be6f9cfa2f1",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Spenatpaj med citron och fetaost",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Pastasås med linser och ajvar relish",
            "MealId": "86aadba2-0708-45d9-a714-15a78f90187c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1453849200000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Broccolisoppa med mjukt bröd och ost",
            "MealId": "099234ba-3ebb-460f-961e-3dbc02de2b8a",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Pastagratäng med blomkål och spenat",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Quinoabiff med kall sweetchilisås och rostad potatis",
            "MealId": "00fb02c0-d514-48bc-a671-4843e3071f72",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1453935600000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Herrgårdskyckling med kokt potatis",
            "MealId": "c48509e1-8e2e-4757-ac05-9c6c6923e2aa",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Falafel med tzatziki och potatis",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Vegetarisk Bourguignon med kokt potatis",
            "MealId": "7000c838-d08b-4399-a587-36556b22af38",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1454022000000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Stekt fisk med remouladsås och kokt potatis",
            "MealId": "2de9af75-8d17-41a2-b5b3-68af5fb18b85",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Milanesesoppa",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Gula ärtbiffar med ratatouille",
            "MealId": "8c42119c-730e-43fa-aae3-ead09c4be6dd",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }]
}, {
    "MenuId": "af77367d-9159-459d-863a-a23b00b6c7f8",
    "MenuName": "Skolmatsedel",
    "WeekNumber": 5,
    "Days": [{
        "InfoText": null,
        "DayMenuDate": new Date(1454281200000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Ost- och skinksås med pasta",
            "MealId": "238e7d82-bf34-4561-ae09-2df00129077a",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Yambalaya m äpple & svamp",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Zucchini piccata med tomatsås och ris",
            "MealId": "1b2c6040-6c76-4828-9f19-b123e80666a3",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1454367600000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Fisk under sprött täcke med kokt potatis",
            "MealId": "663c2b1e-5167-4e98-b608-3d6ef64ebe11",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Solskenslasagnette",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Hemgjorda potatisbullar med vetekornspilaff och kall sås ",
            "MealId": "fe168578-3745-4bbf-9835-ae8e97dabb8d",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1454454000000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Wienerkorv med potatismos",
            "MealId": "b6995939-5949-4acc-ac8a-4e3458ad1586",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Kaneldoftande gryta  med bulgur",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Bakad aubergine med tomatsås och basmatiris",
            "MealId": "f4396f3b-ee2f-4b8f-b862-983087685fd6",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1454540400000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Tomatsoppa med pasta",
            "MealId": "fbe9a8a7-06a4-4436-8898-2523b21e4926",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Dillpototto med bönor",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Vegetarisk lasagne",
            "MealId": "08a9ec84-257d-4665-9733-0c2b8067a62a",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1454626800000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Grillburgare med kall sås och ugnsrostad potatis",
            "MealId": "97bd6558-9bc7-46b6-90eb-8efae9a06da4",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Orientalisk quorngryta med potatis",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Lins och havrebiffar med myntayoghurt och rostade rödbetor",
            "MealId": "1a77a1bc-72a3-4c09-9cd9-78be7ede14c2",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }]
}, {
    "MenuId": "af77367d-9159-459d-863a-a23b00b6c7f8",
    "MenuName": "Skolmatsedel",
    "WeekNumber": 6,
    "Days": [{
        "InfoText": null,
        "DayMenuDate": new Date(1454886000000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Kyckling i currysås med ris",
            "MealId": "9c9fddea-511b-4259-afad-89e48fe6d97e",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Het böngryta med matkorn",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Spenat, fetaost och citronpaj",
            "MealId": "97d515dc-ec93-48f8-9753-300ee99adbc4",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1454972400000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Stekt falukorv med stuvade makaroner",
            "MealId": "90da4b39-b0f6-4427-8b1c-45517544a713",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Ostsoppa med brödkrutonger",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Medelhavsgryta med quinoa",
            "MealId": "4dbf7477-0d1c-4302-b287-f53fd41d1691",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1455058800000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Fiskgratäng med dragon och kokt potatis",
            "MealId": "9fc6e0c8-7d04-4c0b-bd22-27393f80f1dd",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Pastagratäng med fetaost och broccoli",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Falafel med vetekornspilaff och örtaioli",
            "MealId": "e6eb174b-675b-4d04-b077-a795f7bf536e",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1455145200000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Morotsboll med klyftpotatis och tzatziki",
            "MealId": "34e7246a-28c6-4859-8387-3dd40c5bc3de",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Pytt med rotsaker",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Rotfruktsgratäng med fetaostcremé och sautegrönsaker",
            "MealId": "664a1858-78b3-467c-8167-53eb511f9117",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }, {
        "InfoText": null,
        "DayMenuDate": new Date(1455231600000),
        "DayMenus": [{
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 1",
            "DayMenuInfo": "",
            "DayMenuName": "Lasagne med pizzasallad",
            "MealId": "6fe7683b-18db-4c35-a3e3-045ef70bd15d",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "Alt 2",
            "DayMenuInfo": "",
            "DayMenuName": "Bakad potatis med örtkeso",
            "MealId": "450e739f-7b16-432c-967c-6f1a6ef4b63c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }, {
            "PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
            "HasExtendedInfo": false,
            "MealPictureURL": null,
            "MenuAlternativeName": "VegFsk",
            "DayMenuInfo": "",
            "DayMenuName": "Pastasås med linser och ajvar relish",
            "MealId": "86aadba2-0708-45d9-a714-15a78f90187c",
            "ShowDayNutrient": false,
            "ShowWeekNutrient": false,
            "ShowIngredients": false
        }]
    }]
}],
"PortionTypeId": "c00dae2e-5d47-4439-be9b-9bb1e703e555",
"CurrentWeek": 4,
"MenuPresInfoText": null,
"MenuId": ""

}

问题如下:"new Date(12345)"

不能被Microsoft的 JSON 反序列化程序协调,但是"/Date(12345)/"是!

通过使用正则表达式,我能够使用以下代码替换和修复我的 JSON 字符串,然后再将其转换为对象:

private static string FixDataTimeJsonData(string jsonMessage)
    {
        string tempFixed = Regex.Replace(jsonMessage, @"new Date[(]", @"""/Date(");
        tempFixed = Regex.Replace(tempFixed, @"d*([)])", @")/""");
        return tempFixed;
    }

您的 RootObject 应如下所示。

public class DayMenu
{
    public string PortionTypeId { get; set; }
    public bool HasExtendedInfo { get; set; }
    public object MealPictureURL { get; set; }
    public string MenuAlternativeName { get; set; }
    public string DayMenuInfo { get; set; }
    public string DayMenuName { get; set; }
    public string MealId { get; set; }
    public bool ShowDayNutrient { get; set; }
    public bool ShowWeekNutrient { get; set; }
    public bool ShowIngredients { get; set; }
}
public class Day
{
    public object InfoText { get; set; }
    public object DayMenuDate { get; set; }
    public List<DayMenu> DayMenus { get; set; }
}
public class Week
{
    public string MenuId { get; set; }
    public string MenuName { get; set; }
    public int WeekNumber { get; set; }
    public List<Day> Days { get; set; }
}
public class RootObject
{
    public List<Week> Weeks { get; set; }
    public string PortionTypeId { get; set; }
    public int CurrentWeek { get; set; }
    public object MenuPresInfoText { get; set; }
    public string MenuId { get; set; }
}

此对象将成功反序列化。如果您收到此类错误,您可以随时使用本网站 http://json2csharp.com/来验证您的对象。由于空值,那里说"对象"。如果您知道可能的值,则可以将它们更改为字符串或适当的其他类型,但 DayMenuDate 最好是"对象"类型,以便成功反序列化。

最新更新