diff --git a/SimoxUtility/json/eigen_conversion.h b/SimoxUtility/json/eigen_conversion.h index b5ef381e76914f4d9385c2a7a5ffc4e6185a4275..18203b8e1b98ed30ea06db635718723138ba9b91 100644 --- a/SimoxUtility/json/eigen_conversion.h +++ b/SimoxUtility/json/eigen_conversion.h @@ -88,12 +88,19 @@ namespace jsonbase { for (int row = 0; row < matrix.rows(); ++row) { - nlohmann::json jrow = nlohmann::json::array(); - for (int col = 0; col < matrix.cols(); ++col) + if (matrix.cols() > 1) { - jrow.push_back(matrix(row, col)); + nlohmann::json jrow = nlohmann::json::array(); + for (int col = 0; col < matrix.cols(); ++col) + { + jrow.push_back(matrix(row, col)); + } + j.push_back(jrow); + } + else + { + j.push_back(matrix(row, 0)); } - j.push_back(jrow); } } @@ -107,10 +114,17 @@ namespace jsonbase for (std::size_t row = 0; row < j.size(); ++row) { const auto& jrow = j.at(row); - for (std::size_t col = 0; col < jrow.size(); ++col) + if (jrow.is_array()) + { + for (std::size_t col = 0; col < jrow.size(); ++col) + { + const auto& value = jrow.at(col); + matrix(static_cast<Index>(row), static_cast<Index>(col)) = value.get<Scalar>(); + } + } + else { - const auto& value = jrow.at(col); - matrix(static_cast<Index>(row), static_cast<Index>(col)) = value.get<Scalar>(); + matrix(static_cast<Index>(row), 0) = jrow.get<Scalar>(); } } }