Hello, I have a Json string which looks like this [[2,3],[5,6]] I want to read it in an array and add one pair [7,8]. End result should be this [[2,3],[5,6],[7,8]] How can I do this?
Sorry forget the information...it's in esp8266 code I need this in an Arduino code..
Use string functions: https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/
Hannes J. schrieb: > https://stedolan.github.io/jq/manual/ I guess that won't run on an esp8266. But anyway, here is an example for sh:
| 1 | echo [[2,3],[5,6]] | jq -c [.[],[7,8]] | 
Test schrieb: > I want to read it in an array and add one pair [7,8]. You can write a simple JSON parser that does just that. Or you use a general JSON parsing library and construct your data structure with it. I guess adding the additional pair does not require any JSON business. KR, Sebastian
Hello i tried it
| 1 | #include <iostream> | 
| 2 | #include "ArduinoJson.h" | 
| 3 | |
| 4 | int main() {
 | 
| 5 | |
| 6 | StaticJsonDocument<300> doc; | 
| 7 | |
| 8 | char json[] = | 
| 9 | "[[48.756080,2.302038],[48.756080,2.302038]]"; | 
| 10 | |
| 11 | |
| 12 | DeserializationError error = deserializeJson(doc, json); | 
| 13 | |
| 14 | |
| 15 |   if (error) {
 | 
| 16 | std::cerr << "deserializeJson() failed: " << error.c_str() << std::endl; | 
| 17 | return 1; | 
| 18 | } | 
| 19 | |
| 20 | |
| 21 | double longitude = doc[0]; | 
| 22 | |
| 23 | // Print values. | 
| 24 | std::cout << longitude << std::endl; | 
But the output is 0. WHat is wrong??
Please log in before posting. Registration is free and takes only a minute.
  
  Existing account
  
  
  
  Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
  No account? Register here.
 Watch this topic
 Watch this topic Disable multi-page view
 Disable multi-page view