No parameterless constructor defined for type of 'System.String' during JSON deserialization

前端 未结 2 696
栀梦
栀梦 2020-12-05 17:46

This seems like it should be so easy, but I am getting an exception when I try to deserialize some straightforward JSON into a managed type. The exception is:

2条回答
  •  眼角桃花
    2020-12-05 18:20

    I had the same issue and this was what fixed the issue.

    Cheers!

    //Deserializing Json object from string
    DataContractJsonSerializer jsonObjectPersonInfo = 
        new DataContractJsonSerializer(typeof(PersonModel));
    MemoryStream stream = 
        new MemoryStream(Encoding.UTF8.GetBytes(userInfo));
    PersonModel personInfoModel = 
        (PersonModel)jsonObjectPersonInfo.ReadObject(stream);
    

提交回复
热议问题