nlohmann::json jsonMessageOut;
jsonMessageOut[ "action" ] = "updateUnits";
databaseResults R = database.query( "SELECT \"longitude\", \"latitude\" FROM \"units.lonlat\" LIMIT 10;" );
if ( R.size() > 0 ) {
std::vector< std::pair< double, double > > units;
for ( const auto& unit : R )
units.push_back( { unit[ 0 ].as< double >(), unit[ 1 ].as< double >() } );
jsonMessageOut[ "units" ] = units;
}
else
jsonMessageOut[ "units" ] = nlohmann::json::array();
[send]
On the client:
while ( ! ( jsonMessageIn = websocketGetMessageInbound() ).empty() ) { // TODO Look into pushing these into the SDL event queue.
const std::string action = jsonMessageIn[ "action" ];
switch ( networkStringValues[ action ] ) {
...
case networkActionUpdateUnits: {
std::vector< std::pair< double, double > > units = jsonMessageIn[ "units" ];
for ( const auto& unit : units )
std::cout << unit.first << "x" << unit.second << std::endl;
}
...
}
}
- Describe what happens instead.
[[98.02922343358784,-71.97847384808085],[-63.31191659209324,-35.374567995631736],[-110.474999892986,-6.113705884129388],[69.75989939459609,67.16343799507328],[2.3197853267517132,81.05544938056028],[40.16905596844069,80.41366385334712],[-87.83292780117719,-7.74048656814756],[-93.33958934205057,-76.02122165690062],[-23.417427851405677,51.76305532126719],[32.21544673426408,83.85006816965088]] [json.exception.type_error.305] cannot use operator[] with a string argument with array
It seems strange to me that I can see the correct response in the error message but not access it like I would any other array.
-
Describe which system (OS, compiler) you are using.
Emscripten v1.39.10/Clang v8.0.0-3
-
Describe which version of the library you are using (release version, develop branch).
Release v3.7.3
Describe what you want to achieve.
Send array of arrays over a network connection.
Describe what you tried.
On the server:
On the client:
[[98.02922343358784,-71.97847384808085],[-63.31191659209324,-35.374567995631736],[-110.474999892986,-6.113705884129388],[69.75989939459609,67.16343799507328],[2.3197853267517132,81.05544938056028],[40.16905596844069,80.41366385334712],[-87.83292780117719,-7.74048656814756],[-93.33958934205057,-76.02122165690062],[-23.417427851405677,51.76305532126719],[32.21544673426408,83.85006816965088]] [json.exception.type_error.305] cannot use operator[] with a string argument with arrayIt seems strange to me that I can see the correct response in the error message but not access it like I would any other array.
Describe which system (OS, compiler) you are using.
Emscripten v1.39.10/Clang v8.0.0-3Describe which version of the library you are using (release version, develop branch).
Releasev3.7.3