我正在尝试打开一个文件,.json已经将其发送到一个类。但是我在做的时候会出错。
ref class CutAnnotationJSon
{
public:
int index;
String^ nomeTipo;
double pontoX1;
double pontoY1;
double pontoX2;
double pontoY2;
double height;
int r;
int g;
int b;
int numberCut;
};
ref class PanoramicAnnotationJSon
{
public:
int index;
String^ nomeTipo;
double pontoX1;
double pontoY1;
double pontoX2;
double pontoY2;
int r;
int g;
int b;
};
ref class DadosJSon
{
public:
List<PanoramicAnnotationJSon^>^ panoramicAnnotation = gcnew List<PanoramicAnnotationJSon^>;
List<CutAnnotationJSon^>^ cutAnnotation = gcnew List<CutAnnotationJSon^>;
};
用
DadosJSon^ dadosJSon = JsonConvert::DeserializeObject<DadosJSon^>(File::ReadAllText("c:/movie.json"));
错误信息:
103 IntelliSense: more than one instance of overloaded function "Newtonsoft::Json::JsonConvert::DeserializeObject" matches the argument list: function template "T Newtonsoft::Json::JsonConvert::DeserializeObject<T>(System::String ^value)" function template "T Newtonsoft::Json::JsonConvert::DeserializeObject<T>(System::String ^value, ... cli::array<Newtonsoft::Json::JsonConverter ^, 1> ^converters)" argument types are: (System::String ^)
我正在使用Newtonsoft::Json::;
我无法重现该问题。 但是,您可以通过以下方式显式选择JsonConvert.DeserializeObject(String, JsonSerializerSettings)
重载(它执行您想要的操作):
DadosJSon^ dadosJSon = JsonConvert::DeserializeObject<DadosJSon^>(File::ReadAllText("c:/movie.json"), (JsonSerializerSettings ^)nullptr);
传递设置的nullptr
值等效于 JsonConvert::DeserializeObject<DadosJSon^>(File::ReadAllText("c:/movie.json"))
。