Deserializing JSON when fieldnames contain spaces

后端 未结 4 1923
野性不改
野性不改 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:41

    If you want to initialize the Json manually, you can do:

    var jsonString = "{" +
                "'name': 'Fubar'," +
                "'.NET version': '4.0'," +
                "'binding type': 'HTTP'," +
                "}";
            var json = JsonConvert.DeserializeObject(jsonString);            
            return Ok(json);
    

    Don't forget to include using Newtonsoft.Json;

提交回复
热议问题