Json Deserialization error

Please report bugs here. If you are unsure whether something is a bug or an expected behavior, please post it on the "Technical Support" forum instead, and wait for a moderator to handle/move the post.
sebas
Posts: 21
Joined: Fri Oct 27, 2017 7:03 am

Json Deserialization error

Postby sebas » Mon Jan 15, 2018 6:36 am

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'.'
        }
    }
}


sebas
Posts: 21
Joined: Fri Oct 27, 2017 7:03 am

Re: Json Deserialization error

Postby sebas » Mon Jan 15, 2018 6:41 am

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.'

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Json Deserialization error

Postby JS-Support @Userware » Mon Feb 05, 2018 7:14 am

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


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 39 guests

 

 

cron