我想知道在ToString()和(string)转换之间为什么会有值的差异?
许多类似的问题都指出唯一的区别应该是您无法在null值上调用ToString()。
var json = "{\"someKey\":\"Hello world!\"}";
var jsonObject = System.Json.JsonObject.Parse(json);
Assert.AreEqual("Hello world!", (string)jsonObject["someKey"]); //ok
Assert.AreEqual("Hello world!", jsonObject["someKey"].ToString()); //not equal, actual value is "Hello world!" (with quotes in the string)
ToString()
方法。知道这一点就不应该让你再感到困惑了。 - Sinatr