EmbDev.net

Forum: µC & Digital Electronics Manipulation of json


von Test (Guest)


Rate this post
useful
not useful
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?

: Moved by Moderator
von DerEinzigeBernd (Guest)


Rate this post
useful
not useful
Test schrieb:
> How can I do this?

With software.

von Testr (Guest)


Rate this post
useful
not useful
Sorry forget the information...it's in esp8266 code

I need this in an Arduino code..

von Hannes J. (Company: _⌨_) (pnuebergang)


Rate this post
useful
not useful

von Stefan F. (Guest)


Rate this post
useful
not useful

von DPA (Guest)


Rate this post
useful
not useful
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]]

von Sebastian (Guest)


Rate this post
useful
not useful
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

von J. S. (jojos)


Rate this post
useful
not useful
with ArduinoJson Lib: https://arduinojson.org/

von Test (Guest)


Rate this post
useful
not useful
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??

von J. S. (jojos)


Rate this post
useful
not useful
1
double longitude = doc[0][0];

https://wokwi.com/projects/347340486773572179

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
No account? Register here.