Page 1 of 1

Json Deserialization error

Posted: Mon Jan 15, 2018 6:36 am
by sebas

Code: Select all

using System;
using Windows.UI.Xaml;
using CSHTML5.Extensions.Json;

namespace Application2
{
    public sealed partial class App : Application
    {
        public App()
        {
            Exec();
        }

        public class Model2
        {
            public String param3 { get; set; }
        }

        public class Model1
        {
            public Model2 param2 { get; set; } = new Model2() {param3="1" };
            public String param1 { get; set; }

            public Model1() { }

            public Model1(String model)
            {
                param1 = model;
            }
        }

        async void Exec()
        {
            var c1 = new Model1("Asd");

            String s1 = JsonConvert.SerializeObject(c1);
            var x1 = await JsonConvert.DeserializeObject<Model1>(s1); // 'Cannot convert a string to 'Application2.App+Model2'.'
        }
    }
}


Re: Json Deserialization error

Posted: Mon Jan 15, 2018 6:41 am
by sebas
if swap that

Code: Select all

            public String param1 { get; set; }
            public Model2 param2 { get; set; } = new Model2() { param3 = "1" };

than
'Unable to create an instance of type 'System.String'. A common cause is that the type does not have a default public constructor.'

Re: Json Deserialization error

Posted: Mon Feb 05, 2018 7:14 am
by JS-Support @Userware
Hi,

Thanks for your message.

We are working on the implementation of the DataContractJsonSerializer class, which will be much better and more compatible than the JsonConvert class.

Thanks.

Regards,
JS-Support