我只是想在这里创建一个通用方法,但显然没有正确的语法,需要帮助解决这个问题,因为我无法看到我如何能够正常工作:
private static T SerializeJsonToObject<string,T>(string jsonObjectRepresentationsToDeserialize, T typeToDeserializeTo)
{
T serializedTypeFromJson = _jsonSerializer.Deserialize(jsonObjectRepresentationsToDeserialize, typeToDeserializeTo);
return serializedTypeFromJson;
}
答案 0 :(得分:0)
你总能做到:
private static T SerializeJsonToObject<T>(string jsonObjectRepresentationsToDeserialize)
{
return _jsonSerializer.Deserialize<T>(jsonObjectRepresentationsToDeserialize);
}
使用
MyObject obj = SerializeJsonToObject<MyObject>("json object");