2016-02-05 27 views
0

我想打开一个文件,而.json已经将它发送给一个类。 但是我做错了。JsonConvert :: DeserializeObject erro C++ cli

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 ^) 

我使用

+1

我试图重现你的问题,我不能 - 你的代码编译成功。你能否给出一个完整的[mcve](http://stackoverflow.com/help/mcve),包括所有'using namespace'语句?另外,你使用的是什么版本的Json.NET?什么版本的Visual Studio? – dbc

回答

0

我无法重现该问题。不过,你可以明确地选择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"))