JsonConvert :: DeserializeObject erro c ++ cli

时间:2016-02-05 15:52:40

标签: json json.net c++-cli

我试图打开一个文件而.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::;

1 个答案:

答案 0 :(得分: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"))