Deserializing JSON when fieldnames contain spaces

后端 未结 4 1925
野性不改
野性不改 2020-12-31 05:11

I\'m writing a tool to read JSON files. I\'m using the NewtonSoft tool to deserialize the JSOn to a C# class. Here\'s an example fragment:

 \"name\": \"Fubar         


        
4条回答
  •  执念已碎
    2020-12-31 05:59

    Not sure why but this did not work for me. In this example I simply return a null for "BindingType" every time. I actually found it much easier to just download the Json result as a string and then do something like:

      myString = myString.Replace(@"binding type", "BindingType")
    

    You would do this as the step before deserializing.

    Also was less text by a tad. While this worked in my example there will be situations where it may not. For instance if "binding type" was not only a field name but also a piece of data, this method would change it as well as the field name which may not be desirable.

提交回复
热议问题