我需要弄清楚 JObject 是否具有与 CustomObject 类型匹配的正确属性。我使用 JObject.ToObject 希望如果属性与 CustomObject 不匹配它会失败,但它仍然创建所有属性为 null 的 CustomObject。
无论如何,我可以在调用 ToObject 之前验证它吗?
class CustomObject
{
string fname;
string lname;
}
void test()
{
string json = "{\"User\": \"Hello\"}";
JObject jsonObj = JObject.Parse(json);
CustomObject custObj = null;
// this always creates CustomObject instance
// I need to validate that jsonObj has valid attributes that match CustomObject
custObj = JObject.ToObject<CustomObject>();
犯罪嫌疑人X
qq_遁去的一_1
GCT1015
相关分类