Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eigen 来自_json()的vectorXd?_Eigen_Nlohmann Json - Fatal编程技术网

Eigen 来自_json()的vectorXd?

Eigen 来自_json()的vectorXd?,eigen,nlohmann-json,Eigen,Nlohmann Json,我正在尝试使用eigen::VectorXd和nlohmann json库实现类的json序列化。将类存储为JSON字符串不是问题。如何从JSON解析VectorXd?是否有其他更适合此任务的库 #include "json.hpp" class TransformationStep { public: VectorXd support_vector; int number; TransformationStep(int number_param, Vecto

我正在尝试使用eigen::VectorXd和nlohmann json库实现类的json序列化。将类存储为JSON字符串不是问题。如何从JSON解析VectorXd?是否有其他更适合此任务的库

#include "json.hpp"

class TransformationStep {
public:
  VectorXd support_vector;
  int number;

  TransformationStep(int number_param, VectorXd support_vectorParam) {
    number = number_param;
    support_vector = support_vectorParam;
  }

  ~TransformationStep() {
  }

  //json serialization
  void to_json(nlohmann::json &j);
  void from_json(const nlohmann::json &j);
};


void TransformationStep::to_json(nlohmann::json &j) {
  j["number"] = number;
  j["support_vector"] = support_vector;
}


void Ftf::from_json(const nlohmann::json &j)
{
    number = (j.at("number").get<int>());
    //support_vector = j["support_vector"].get<VectorXd>()); //???
}
我想出了

void vector_from_json(VectorXd& vector, const nlohmann::json &j) {
  vector.resize(j.size());
  size_t element_index=0;
  for (const auto& element : j) {
    vector(element_index++) = (double) element;
  }
}
我想出了

void vector_from_json(VectorXd& vector, const nlohmann::json &j) {
  vector.resize(j.size());
  size_t element_index=0;
  for (const auto& element : j) {
    vector(element_index++) = (double) element;
  }
}

你好,我也遇到了类似的问题。这里有一个链接可能对你有所帮助。你好,我也遇到了类似的问题。这里有一个链接可能对你有所帮助。