nlohmann/json:如何将字符串转换为列表并遍历该列表?

huangapple go评论78阅读模式
英文:

nlohmann/json: how to convert a string to a list and iterate over this list?

问题

nlohmann/json:如何将字符串转换为列表并迭代该列表?

我在一个非常特殊的情况下,字符串中包含一个列表。请参阅下面的“Body”和“lidar_calibration”键:关联的值是嵌套在字符串“[]”中的列表。

#include <iostream>
#include <fstream>
#include <sstream>
#include <nlohmann/json.hpp>

int main() {
  {
    std::ifstream inp("calibration.json");
    std::string out; while(inp >> out) std::cout << out; std::cout << std::endl;
  }
  std::cout << std::endl;
  {
    std::ifstream inp("calibration.json");
    nlohmann::json inpJson = nlohmann::json::parse(inp);
    std::cout << inpJson << std::endl;
  }
  std::cout << std::endl;
  {
    std::ifstream inp("calibration.json");
    nlohmann::json inpJson = nlohmann::json::parse(inp);
    std::stringstream str; str << inpJson["Body"]["lidar_calibration"];
    nlohmann::json calibJson = nlohmann::json::parse(str);
    std::cout << calibJson << std::endl;
  }
  std::cout << std::endl;
  {
    std::ifstream inp("calibration.json");
    nlohmann::json inpJson = nlohmann::json::parse(inp);
    std::stringstream str; str << inpJson["Body"]["lidar_calibration"];
    nlohmann::json calibJson = nlohmann::json::parse(str);
    for (auto const & calib : calibJson) std::cout << calib << std::endl;
  }
}
$ g++ -I /usr/include/nlohmann -o calibration calibration.cpp

$ ./calibration 
{"Head":{"ErrorCode":"0","Message":"Success"},"Body":{"lidar_calibration":"[{\"i\":1,\"e\":\"15.039\",\"a\":\"0.301\"},{\"i\":2,\"e\":\"14.025\",\"a\":\"0.313\"},{\"i\":3,\"e\":\"13.019\",\"a\":\"0.306\"},{\"i\":4,\"e\":\"12.012\",\"a\":\"0.299\"},{\"i\":5,\"e\":\"11.009\",\"a\":\"0.291\"},{\"i\":6,\"e\":\"10.005\",\"a\":\"0.292\"},{\"i\":7,\"e\":\"9.002\",\"a\":\"0.288\"},{\"i\":8,\"e\":\"8.006\",\"a\":\"0.280\"},{\"i\":9,\"e\":\"7.005\",\"a\":\"0.278\"},{\"i\":10,\"e\":\"6.007\",\"a\":\"0.282\"},{\"i\":11,\"e\":\"5.009\",\"a\":\"0.274\"},{\"i\":12,\"e\":\"4.009\",\"a\":\"0.278\"},{\"i\":13,\"e\":\"3.015\",\"a\":\"0.271\"},{\"i\":14,\"e\":\"2.021\",\"a\":\"0.271\"},{\"i\":15,\"e\":\"1.029\",\"a\":\"0.272\"},{\"i\":16,\"e\":\"0.036\",\"a\":\"0.266\"},{\"i\":17,\"e\":\"-0.957\",\"a\":\"0.262\"},{\"i\":18,\"e\":\"-1.954\",\"a\":\"0.266\"},{\"i\":19,\"e\":\"-2.949\",\"a\":\"0.260\"},{\"i\":20,\"e\":\"-3.945\",\"a\":\"0.254\"},{\"i\":21,\"e\":\"-4.940\",\"a\":\"0.245\"},{\"i\":22,\"e\":\"-5.940\",\"a\":\"0.243\"},{\"i\":23,\"e\":\"-6.937\",\"a\":\"0.243\"},{\"i\":24,\"e\":\"-7.934\",\"a\":\"0.241\"},{\"i\":25,\"e\":\"-8.936\",\"a\":\"0.232\"},{\"i\":26,\"e\":\"-9.936\",\"a\":\"0.238\"},{\"i\":27,\"e\":\"-10.940\",\"a\":\"0.236\"},{\"i\":28,\"e\":\"-11.946\",\"a\":\"0.223\"},{\"i\":29,\"e\":\"-12.950\",\"a\":\"0.215\"},{\"i\":30,\"e\":\"-13.959\",\"a\":\"0.211\"},{\"i\":31,\"e\":\"-14.974\",\"a\":\"0.207\"},{\"i\":32,\"e\":\"-15.992\",\"a\":\"0.205\"}]"}}
{"Body":{"lidar_calibration":"[{\"i\":1,\"e\":\"15.039\",\"a\":\"0.301\"},{\"i\":2,\"e\":\"14.025

<details>
<summary>英文:</summary>

nlohmann/json: how to convert a string to a list and iterate over this list?

I am in a very specific case with a list wrapped into a string. See the &quot;Body&quot; and &quot;lidar_calibration&quot; keys below: the associated value is a list embedded into a string `&quot;[]&quot;`.

&gt; cat calibration.json

{
"Head": {
"ErrorCode": "0",
"Message": "Success"
},
"Body": {
"lidar_calibration": "[{&quot;i&quot;:1,&quot;e&quot;:&quot;15.039&quot;,&quot;a&quot;:&quot;0.301&quot;},{&quot;i&quot;:2,&quot;e&quot;:&quot;14.025&quot;,&quot;a&quot;:&quot;0.313&quot;},{&quot;i&quot;:3,&quot;e&quot;:&quot;13.019&quot;,&quot;a&quot;:&quot;0.306&quot;},{&quot;i&quot;:4,&quot;e&quot;:&quot;12.012&quot;,&quot;a&quot;:&quot;0.299&quot;},{&quot;i&quot;:5,&quot;e&quot;:&quot;11.009&quot;,&quot;a&quot;:&quot;0.291&quot;},{&quot;i&quot;:6,&quot;e&quot;:&quot;10.005&quot;,&quot;a&quot;:&quot;0.292&quot;},{&quot;i&quot;:7,&quot;e&quot;:&quot;9.002&quot;,&quot;a&quot;:&quot;0.288&quot;},{&quot;i&quot;:8,&quot;e&quot;:&quot;8.006&quot;,&quot;a&quot;:&quot;0.280&quot;},{&quot;i&quot;:9,&quot;e&quot;:&quot;7.005&quot;,&quot;a&quot;:&quot;0.278&quot;},{&quot;i&quot;:10,&quot;e&quot;:&quot;6.007&quot;,&quot;a&quot;:&quot;0.282&quot;},{&quot;i&quot;:11,&quot;e&quot;:&quot;5.009&quot;,&quot;a&quot;:&quot;0.274&quot;},{&quot;i&quot;:12,&quot;e&quot;:&quot;4.009&quot;,&quot;a&quot;:&quot;0.278&quot;},{&quot;i&quot;:13,&quot;e&quot;:&quot;3.015&quot;,&quot;a&quot;:&quot;0.271&quot;},{&quot;i&quot;:14,&quot;e&quot;:&quot;2.021&quot;,&quot;a&quot;:&quot;0.271&quot;},{&quot;i&quot;:15,&quot;e&quot;:&quot;1.029&quot;,&quot;a&quot;:&quot;0.272&quot;},{&quot;i&quot;:16,&quot;e&quot;:&quot;0.036&quot;,&quot;a&quot;:&quot;0.266&quot;},{&quot;i&quot;:17,&quot;e&quot;:&quot;-0.957&quot;,&quot;a&quot;:&quot;0.262&quot;},{&quot;i&quot;:18,&quot;e&quot;:&quot;-1.954&quot;,&quot;a&quot;:&quot;0.266&quot;},{&quot;i&quot;:19,&quot;e&quot;:&quot;-2.949&quot;,&quot;a&quot;:&quot;0.260&quot;},{&quot;i&quot;:20,&quot;e&quot;:&quot;-3.945&quot;,&quot;a&quot;:&quot;0.254&quot;},{&quot;i&quot;:21,&quot;e&quot;:&quot;-4.940&quot;,&quot;a&quot;:&quot;0.245&quot;},{&quot;i&quot;:22,&quot;e&quot;:&quot;-5.940&quot;,&quot;a&quot;:&quot;0.243&quot;},{&quot;i&quot;:23,&quot;e&quot;:&quot;-6.937&quot;,&quot;a&quot;:&quot;0.243&quot;},{&quot;i&quot;:24,&quot;e&quot;:&quot;-7.934&quot;,&quot;a&quot;:&quot;0.241&quot;},{&quot;i&quot;:25,&quot;e&quot;:&quot;-8.936&quot;,&quot;a&quot;:&quot;0.232&quot;},{&quot;i&quot;:26,&quot;e&quot;:&quot;-9.936&quot;,&quot;a&quot;:&quot;0.238&quot;},{&quot;i&quot;:27,&quot;e&quot;:&quot;-10.940&quot;,&quot;a&quot;:&quot;0.236&quot;},{&quot;i&quot;:28,&quot;e&quot;:&quot;-11.946&quot;,&quot;a&quot;:&quot;0.223&quot;},{&quot;i&quot;:29,&quot;e&quot;:&quot;-12.950&quot;,&quot;a&quot;:&quot;0.215&quot;},{&quot;i&quot;:30,&quot;e&quot;:&quot;-13.959&quot;,&quot;a&quot;:&quot;0.211&quot;},{&quot;i&quot;:31,&quot;e&quot;:&quot;-14.974&quot;,&quot;a&quot;:&quot;0.207&quot;},{&quot;i&quot;:32,&quot;e&quot;:&quot;-15.992&quot;,&quot;a&quot;:&quot;0.205&quot;}]"
}
}


&gt; cat calibration.cpp 
```cpp
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;nlohmann/json.hpp&gt;

int main() {
  {
    std::ifstream inp(&quot;calibration.json&quot;);
    std::string out; while(inp &gt;&gt; out) std::cout &lt;&lt; out; std::cout &lt;&lt; std::endl;
  }
  std::cout &lt;&lt; std::endl;
  {
    std::ifstream inp(&quot;calibration.json&quot;);
    nlohmann::json inpJson = nlohmann::json::parse(inp);
    std::cout &lt;&lt; inpJson &lt;&lt; std::endl;
  }
  std::cout &lt;&lt; std::endl;
  {
    std::ifstream inp(&quot;calibration.json&quot;);
    nlohmann::json inpJson = nlohmann::json::parse(inp);
    std::stringstream str; str &lt;&lt; inpJson[&quot;Body&quot;][&quot;lidar_calibration&quot;];
    nlohmann::json calibJson = nlohmann::json::parse(str);
    std::cout &lt;&lt; calibJson &lt;&lt; std::endl;
  }
  std::cout &lt;&lt; std::endl;
  {
    std::ifstream inp(&quot;calibration.json&quot;);
    nlohmann::json inpJson = nlohmann::json::parse(inp);
    std::stringstream str; str &lt;&lt; inpJson[&quot;Body&quot;][&quot;lidar_calibration&quot;];
    nlohmann::json calibJson = nlohmann::json::parse(str);
    for (auto const &amp; calib : calibJson) std::cout &lt;&lt; calib &lt;&lt; std::endl;
  }
}
$ g++ -I /usr/include/nlohmann -o calibration calibration.cpp 
$ ./calibration 
{&quot;Head&quot;:{&quot;ErrorCode&quot;:&quot;0&quot;,&quot;Message&quot;:&quot;Success&quot;},&quot;Body&quot;:{&quot;lidar_calibration&quot;:&quot;[{\&quot;i\&quot;:1,\&quot;e\&quot;:\&quot;15.039\&quot;,\&quot;a\&quot;:\&quot;0.301\&quot;},{\&quot;i\&quot;:2,\&quot;e\&quot;:\&quot;14.025\&quot;,\&quot;a\&quot;:\&quot;0.313\&quot;},{\&quot;i\&quot;:3,\&quot;e\&quot;:\&quot;13.019\&quot;,\&quot;a\&quot;:\&quot;0.306\&quot;},{\&quot;i\&quot;:4,\&quot;e\&quot;:\&quot;12.012\&quot;,\&quot;a\&quot;:\&quot;0.299\&quot;},{\&quot;i\&quot;:5,\&quot;e\&quot;:\&quot;11.009\&quot;,\&quot;a\&quot;:\&quot;0.291\&quot;},{\&quot;i\&quot;:6,\&quot;e\&quot;:\&quot;10.005\&quot;,\&quot;a\&quot;:\&quot;0.292\&quot;},{\&quot;i\&quot;:7,\&quot;e\&quot;:\&quot;9.002\&quot;,\&quot;a\&quot;:\&quot;0.288\&quot;},{\&quot;i\&quot;:8,\&quot;e\&quot;:\&quot;8.006\&quot;,\&quot;a\&quot;:\&quot;0.280\&quot;},{\&quot;i\&quot;:9,\&quot;e\&quot;:\&quot;7.005\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:10,\&quot;e\&quot;:\&quot;6.007\&quot;,\&quot;a\&quot;:\&quot;0.282\&quot;},{\&quot;i\&quot;:11,\&quot;e\&quot;:\&quot;5.009\&quot;,\&quot;a\&quot;:\&quot;0.274\&quot;},{\&quot;i\&quot;:12,\&quot;e\&quot;:\&quot;4.009\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:13,\&quot;e\&quot;:\&quot;3.015\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:14,\&quot;e\&quot;:\&quot;2.021\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:15,\&quot;e\&quot;:\&quot;1.029\&quot;,\&quot;a\&quot;:\&quot;0.272\&quot;},{\&quot;i\&quot;:16,\&quot;e\&quot;:\&quot;0.036\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:17,\&quot;e\&quot;:\&quot;-0.957\&quot;,\&quot;a\&quot;:\&quot;0.262\&quot;},{\&quot;i\&quot;:18,\&quot;e\&quot;:\&quot;-1.954\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:19,\&quot;e\&quot;:\&quot;-2.949\&quot;,\&quot;a\&quot;:\&quot;0.260\&quot;},{\&quot;i\&quot;:20,\&quot;e\&quot;:\&quot;-3.945\&quot;,\&quot;a\&quot;:\&quot;0.254\&quot;},{\&quot;i\&quot;:21,\&quot;e\&quot;:\&quot;-4.940\&quot;,\&quot;a\&quot;:\&quot;0.245\&quot;},{\&quot;i\&quot;:22,\&quot;e\&quot;:\&quot;-5.940\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:23,\&quot;e\&quot;:\&quot;-6.937\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:24,\&quot;e\&quot;:\&quot;-7.934\&quot;,\&quot;a\&quot;:\&quot;0.241\&quot;},{\&quot;i\&quot;:25,\&quot;e\&quot;:\&quot;-8.936\&quot;,\&quot;a\&quot;:\&quot;0.232\&quot;},{\&quot;i\&quot;:26,\&quot;e\&quot;:\&quot;-9.936\&quot;,\&quot;a\&quot;:\&quot;0.238\&quot;},{\&quot;i\&quot;:27,\&quot;e\&quot;:\&quot;-10.940\&quot;,\&quot;a\&quot;:\&quot;0.236\&quot;},{\&quot;i\&quot;:28,\&quot;e\&quot;:\&quot;-11.946\&quot;,\&quot;a\&quot;:\&quot;0.223\&quot;},{\&quot;i\&quot;:29,\&quot;e\&quot;:\&quot;-12.950\&quot;,\&quot;a\&quot;:\&quot;0.215\&quot;},{\&quot;i\&quot;:30,\&quot;e\&quot;:\&quot;-13.959\&quot;,\&quot;a\&quot;:\&quot;0.211\&quot;},{\&quot;i\&quot;:31,\&quot;e\&quot;:\&quot;-14.974\&quot;,\&quot;a\&quot;:\&quot;0.207\&quot;},{\&quot;i\&quot;:32,\&quot;e\&quot;:\&quot;-15.992\&quot;,\&quot;a\&quot;:\&quot;0.205\&quot;}]&quot;}}
{&quot;Body&quot;:{&quot;lidar_calibration&quot;:&quot;[{\&quot;i\&quot;:1,\&quot;e\&quot;:\&quot;15.039\&quot;,\&quot;a\&quot;:\&quot;0.301\&quot;},{\&quot;i\&quot;:2,\&quot;e\&quot;:\&quot;14.025\&quot;,\&quot;a\&quot;:\&quot;0.313\&quot;},{\&quot;i\&quot;:3,\&quot;e\&quot;:\&quot;13.019\&quot;,\&quot;a\&quot;:\&quot;0.306\&quot;},{\&quot;i\&quot;:4,\&quot;e\&quot;:\&quot;12.012\&quot;,\&quot;a\&quot;:\&quot;0.299\&quot;},{\&quot;i\&quot;:5,\&quot;e\&quot;:\&quot;11.009\&quot;,\&quot;a\&quot;:\&quot;0.291\&quot;},{\&quot;i\&quot;:6,\&quot;e\&quot;:\&quot;10.005\&quot;,\&quot;a\&quot;:\&quot;0.292\&quot;},{\&quot;i\&quot;:7,\&quot;e\&quot;:\&quot;9.002\&quot;,\&quot;a\&quot;:\&quot;0.288\&quot;},{\&quot;i\&quot;:8,\&quot;e\&quot;:\&quot;8.006\&quot;,\&quot;a\&quot;:\&quot;0.280\&quot;},{\&quot;i\&quot;:9,\&quot;e\&quot;:\&quot;7.005\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:10,\&quot;e\&quot;:\&quot;6.007\&quot;,\&quot;a\&quot;:\&quot;0.282\&quot;},{\&quot;i\&quot;:11,\&quot;e\&quot;:\&quot;5.009\&quot;,\&quot;a\&quot;:\&quot;0.274\&quot;},{\&quot;i\&quot;:12,\&quot;e\&quot;:\&quot;4.009\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:13,\&quot;e\&quot;:\&quot;3.015\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:14,\&quot;e\&quot;:\&quot;2.021\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:15,\&quot;e\&quot;:\&quot;1.029\&quot;,\&quot;a\&quot;:\&quot;0.272\&quot;},{\&quot;i\&quot;:16,\&quot;e\&quot;:\&quot;0.036\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:17,\&quot;e\&quot;:\&quot;-0.957\&quot;,\&quot;a\&quot;:\&quot;0.262\&quot;},{\&quot;i\&quot;:18,\&quot;e\&quot;:\&quot;-1.954\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:19,\&quot;e\&quot;:\&quot;-2.949\&quot;,\&quot;a\&quot;:\&quot;0.260\&quot;},{\&quot;i\&quot;:20,\&quot;e\&quot;:\&quot;-3.945\&quot;,\&quot;a\&quot;:\&quot;0.254\&quot;},{\&quot;i\&quot;:21,\&quot;e\&quot;:\&quot;-4.940\&quot;,\&quot;a\&quot;:\&quot;0.245\&quot;},{\&quot;i\&quot;:22,\&quot;e\&quot;:\&quot;-5.940\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:23,\&quot;e\&quot;:\&quot;-6.937\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:24,\&quot;e\&quot;:\&quot;-7.934\&quot;,\&quot;a\&quot;:\&quot;0.241\&quot;},{\&quot;i\&quot;:25,\&quot;e\&quot;:\&quot;-8.936\&quot;,\&quot;a\&quot;:\&quot;0.232\&quot;},{\&quot;i\&quot;:26,\&quot;e\&quot;:\&quot;-9.936\&quot;,\&quot;a\&quot;:\&quot;0.238\&quot;},{\&quot;i\&quot;:27,\&quot;e\&quot;:\&quot;-10.940\&quot;,\&quot;a\&quot;:\&quot;0.236\&quot;},{\&quot;i\&quot;:28,\&quot;e\&quot;:\&quot;-11.946\&quot;,\&quot;a\&quot;:\&quot;0.223\&quot;},{\&quot;i\&quot;:29,\&quot;e\&quot;:\&quot;-12.950\&quot;,\&quot;a\&quot;:\&quot;0.215\&quot;},{\&quot;i\&quot;:30,\&quot;e\&quot;:\&quot;-13.959\&quot;,\&quot;a\&quot;:\&quot;0.211\&quot;},{\&quot;i\&quot;:31,\&quot;e\&quot;:\&quot;-14.974\&quot;,\&quot;a\&quot;:\&quot;0.207\&quot;},{\&quot;i\&quot;:32,\&quot;e\&quot;:\&quot;-15.992\&quot;,\&quot;a\&quot;:\&quot;0.205\&quot;}]&quot;},&quot;Head&quot;:{&quot;ErrorCode&quot;:&quot;0&quot;,&quot;Message&quot;:&quot;Success&quot;}}
&quot;[{\&quot;i\&quot;:1,\&quot;e\&quot;:\&quot;15.039\&quot;,\&quot;a\&quot;:\&quot;0.301\&quot;},{\&quot;i\&quot;:2,\&quot;e\&quot;:\&quot;14.025\&quot;,\&quot;a\&quot;:\&quot;0.313\&quot;},{\&quot;i\&quot;:3,\&quot;e\&quot;:\&quot;13.019\&quot;,\&quot;a\&quot;:\&quot;0.306\&quot;},{\&quot;i\&quot;:4,\&quot;e\&quot;:\&quot;12.012\&quot;,\&quot;a\&quot;:\&quot;0.299\&quot;},{\&quot;i\&quot;:5,\&quot;e\&quot;:\&quot;11.009\&quot;,\&quot;a\&quot;:\&quot;0.291\&quot;},{\&quot;i\&quot;:6,\&quot;e\&quot;:\&quot;10.005\&quot;,\&quot;a\&quot;:\&quot;0.292\&quot;},{\&quot;i\&quot;:7,\&quot;e\&quot;:\&quot;9.002\&quot;,\&quot;a\&quot;:\&quot;0.288\&quot;},{\&quot;i\&quot;:8,\&quot;e\&quot;:\&quot;8.006\&quot;,\&quot;a\&quot;:\&quot;0.280\&quot;},{\&quot;i\&quot;:9,\&quot;e\&quot;:\&quot;7.005\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:10,\&quot;e\&quot;:\&quot;6.007\&quot;,\&quot;a\&quot;:\&quot;0.282\&quot;},{\&quot;i\&quot;:11,\&quot;e\&quot;:\&quot;5.009\&quot;,\&quot;a\&quot;:\&quot;0.274\&quot;},{\&quot;i\&quot;:12,\&quot;e\&quot;:\&quot;4.009\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:13,\&quot;e\&quot;:\&quot;3.015\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:14,\&quot;e\&quot;:\&quot;2.021\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:15,\&quot;e\&quot;:\&quot;1.029\&quot;,\&quot;a\&quot;:\&quot;0.272\&quot;},{\&quot;i\&quot;:16,\&quot;e\&quot;:\&quot;0.036\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:17,\&quot;e\&quot;:\&quot;-0.957\&quot;,\&quot;a\&quot;:\&quot;0.262\&quot;},{\&quot;i\&quot;:18,\&quot;e\&quot;:\&quot;-1.954\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:19,\&quot;e\&quot;:\&quot;-2.949\&quot;,\&quot;a\&quot;:\&quot;0.260\&quot;},{\&quot;i\&quot;:20,\&quot;e\&quot;:\&quot;-3.945\&quot;,\&quot;a\&quot;:\&quot;0.254\&quot;},{\&quot;i\&quot;:21,\&quot;e\&quot;:\&quot;-4.940\&quot;,\&quot;a\&quot;:\&quot;0.245\&quot;},{\&quot;i\&quot;:22,\&quot;e\&quot;:\&quot;-5.940\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:23,\&quot;e\&quot;:\&quot;-6.937\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:24,\&quot;e\&quot;:\&quot;-7.934\&quot;,\&quot;a\&quot;:\&quot;0.241\&quot;},{\&quot;i\&quot;:25,\&quot;e\&quot;:\&quot;-8.936\&quot;,\&quot;a\&quot;:\&quot;0.232\&quot;},{\&quot;i\&quot;:26,\&quot;e\&quot;:\&quot;-9.936\&quot;,\&quot;a\&quot;:\&quot;0.238\&quot;},{\&quot;i\&quot;:27,\&quot;e\&quot;:\&quot;-10.940\&quot;,\&quot;a\&quot;:\&quot;0.236\&quot;},{\&quot;i\&quot;:28,\&quot;e\&quot;:\&quot;-11.946\&quot;,\&quot;a\&quot;:\&quot;0.223\&quot;},{\&quot;i\&quot;:29,\&quot;e\&quot;:\&quot;-12.950\&quot;,\&quot;a\&quot;:\&quot;0.215\&quot;},{\&quot;i\&quot;:30,\&quot;e\&quot;:\&quot;-13.959\&quot;,\&quot;a\&quot;:\&quot;0.211\&quot;},{\&quot;i\&quot;:31,\&quot;e\&quot;:\&quot;-14.974\&quot;,\&quot;a\&quot;:\&quot;0.207\&quot;},{\&quot;i\&quot;:32,\&quot;e\&quot;:\&quot;-15.992\&quot;,\&quot;a\&quot;:\&quot;0.205\&quot;}]&quot;
&quot;[{\&quot;i\&quot;:1,\&quot;e\&quot;:\&quot;15.039\&quot;,\&quot;a\&quot;:\&quot;0.301\&quot;},{\&quot;i\&quot;:2,\&quot;e\&quot;:\&quot;14.025\&quot;,\&quot;a\&quot;:\&quot;0.313\&quot;},{\&quot;i\&quot;:3,\&quot;e\&quot;:\&quot;13.019\&quot;,\&quot;a\&quot;:\&quot;0.306\&quot;},{\&quot;i\&quot;:4,\&quot;e\&quot;:\&quot;12.012\&quot;,\&quot;a\&quot;:\&quot;0.299\&quot;},{\&quot;i\&quot;:5,\&quot;e\&quot;:\&quot;11.009\&quot;,\&quot;a\&quot;:\&quot;0.291\&quot;},{\&quot;i\&quot;:6,\&quot;e\&quot;:\&quot;10.005\&quot;,\&quot;a\&quot;:\&quot;0.292\&quot;},{\&quot;i\&quot;:7,\&quot;e\&quot;:\&quot;9.002\&quot;,\&quot;a\&quot;:\&quot;0.288\&quot;},{\&quot;i\&quot;:8,\&quot;e\&quot;:\&quot;8.006\&quot;,\&quot;a\&quot;:\&quot;0.280\&quot;},{\&quot;i\&quot;:9,\&quot;e\&quot;:\&quot;7.005\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:10,\&quot;e\&quot;:\&quot;6.007\&quot;,\&quot;a\&quot;:\&quot;0.282\&quot;},{\&quot;i\&quot;:11,\&quot;e\&quot;:\&quot;5.009\&quot;,\&quot;a\&quot;:\&quot;0.274\&quot;},{\&quot;i\&quot;:12,\&quot;e\&quot;:\&quot;4.009\&quot;,\&quot;a\&quot;:\&quot;0.278\&quot;},{\&quot;i\&quot;:13,\&quot;e\&quot;:\&quot;3.015\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:14,\&quot;e\&quot;:\&quot;2.021\&quot;,\&quot;a\&quot;:\&quot;0.271\&quot;},{\&quot;i\&quot;:15,\&quot;e\&quot;:\&quot;1.029\&quot;,\&quot;a\&quot;:\&quot;0.272\&quot;},{\&quot;i\&quot;:16,\&quot;e\&quot;:\&quot;0.036\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:17,\&quot;e\&quot;:\&quot;-0.957\&quot;,\&quot;a\&quot;:\&quot;0.262\&quot;},{\&quot;i\&quot;:18,\&quot;e\&quot;:\&quot;-1.954\&quot;,\&quot;a\&quot;:\&quot;0.266\&quot;},{\&quot;i\&quot;:19,\&quot;e\&quot;:\&quot;-2.949\&quot;,\&quot;a\&quot;:\&quot;0.260\&quot;},{\&quot;i\&quot;:20,\&quot;e\&quot;:\&quot;-3.945\&quot;,\&quot;a\&quot;:\&quot;0.254\&quot;},{\&quot;i\&quot;:21,\&quot;e\&quot;:\&quot;-4.940\&quot;,\&quot;a\&quot;:\&quot;0.245\&quot;},{\&quot;i\&quot;:22,\&quot;e\&quot;:\&quot;-5.940\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:23,\&quot;e\&quot;:\&quot;-6.937\&quot;,\&quot;a\&quot;:\&quot;0.243\&quot;},{\&quot;i\&quot;:24,\&quot;e\&quot;:\&quot;-7.934\&quot;,\&quot;a\&quot;:\&quot;0.241\&quot;},{\&quot;i\&quot;:25,\&quot;e\&quot;:\&quot;-8.936\&quot;,\&quot;a\&quot;:\&quot;0.232\&quot;},{\&quot;i\&quot;:26,\&quot;e\&quot;:\&quot;-9.936\&quot;,\&quot;a\&quot;:\&quot;0.238\&quot;},{\&quot;i\&quot;:27,\&quot;e\&quot;:\&quot;-10.940\&quot;,\&quot;a\&quot;:\&quot;0.236\&quot;},{\&quot;i\&quot;:28,\&quot;e\&quot;:\&quot;-11.946\&quot;,\&quot;a\&quot;:\&quot;0.223\&quot;},{\&quot;i\&quot;:29,\&quot;e\&quot;:\&quot;-12.950\&quot;,\&quot;a\&quot;:\&quot;0.215\&quot;},{\&quot;i\&quot;:30,\&quot;e\&quot;:\&quot;-13.959\&quot;,\&quot;a\&quot;:\&quot;0.211\&quot;},{\&quot;i\&quot;:31,\&quot;e\&quot;:\&quot;-14.974\&quot;,\&quot;a\&quot;:\&quot;0.207\&quot;},{\&quot;i\&quot;:32,\&quot;e\&quot;:\&quot;-15.992\&quot;,\&quot;a\&quot;:\&quot;0.205\&quot;}]&quot;

How can I iterate over this list?

答案1

得分: 2

将其转换为字符串,而不是使用operator<<将其序列化为另一个JSON。

英文:

Just:

std::string str = inpJson[&quot;Body&quot;][&quot;lidar_calibration&quot;];
nlohmann::json calibJson = nlohmann::json::parse(str);

Convert it to string instead of serializing with operator<< to another json.

huangapple
  • 本文由 发表于 2023年7月27日 18:45:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76778964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定