c++ - Send vector<int> through serial in json format -


for json parsing use https://github.com/nlohmann/json

my code:

... #include <algorithm> #include <vector> #include <sstream> #include "json.hpp"     using namespace std; using json = nlohmann::json;  int main(int argc, char *argv[]) {     // read json file     std::stringstream ss;     std::ifstream i("filee.json");     json j_complete = json::parse(i);     std::vector < int > data_send_to_led;     (int =0; i<j_complete["tablica"].size(); i++){         data_send_to_led.push_back(j_complete["tablica"][i].get<int>());     }     (int =0; i<data_send_to_led.size(); i++){         cout <<"data send: "<< data_send_to_led[i]<<endl;     }     json j_vec(data_send_to_led);     int* pv = &data_send_to_led[0];     ...     n = write(sockfd,pv, data_send_to_led.size());  } 

how can send vector data_send_to_led json through serial?

without knowing details of code

json j_vec(data_send_to_led); // makes json text? int* pv = &data_send_to_led[0]; // hope don't data_send_to_led after point. ... n = write(sockfd,pv, data_send_to_led.size()); // sends data binary 

what might need pointer data in j_vec, j_vec.data(), , size might j_vec.size().

n = write(sockfd, j_vec.data(), j_vec.size());  

the size might need +1 0 terminate over.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -