json.net deserialization throwing exception when json is loaded from project resource

前端 未结 2 407
难免孤独
难免孤独 2021-01-26 08:25

This is the deserialization that produces the problem:

public MyType ProblematicDeserialization(jsonString)
{
    return Newtonsoft.Json.JsonConvert.DeserializeO         


        
相关标签:
2条回答
  • 2021-01-26 08:28

    After /u/dbc's comment that the byte sequence indicated that the encoding of the resource file was UTF-8-BOM, I solved it this way:

    • I went to the source file in disk that was treated as a resource in my project
    • I edited it with Notepad++
    • Encoding -> Convert to UTF-8

    After that, the exact same code posted in the original post worked perfectly.

    0 讨论(0)
  • 2021-01-26 08:35

    First you sample does not compile, I assume you mean

    public MyType ProblematicDeserialization(s)
    {
        return Newtonsoft.Json.JsonConvert.DeserializeObject<MyType)(s);   
    }
    
    0 讨论(0)
提交回复
热议问题