A
A
alucky2017-11-22 20:51:04
Arduino
alucky, 2017-11-22 20:51:04

How to use ArduinoJson in own class?

I can't figure out how to create my own class that will process json.
the class is like this:

class Cfg {

private: 
DynamicJsonBuffer buff;
JsonObject cfg;

public: 
 JsonObject& get() {
  return cfg;
 }
 
 void set(char json[]){
   cfg = buff.parseObject(json);
 }
};

I want to use like this:
int main()
{
  Cfg jconfig;
  char j[] = "{\"aa\": \"bbb\"}";
  
  jconfig.set(j);
  
  std::cout << jconfig.get() << std::endl;

  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hoksmur, 2017-11-30
@Hoksmur

First, decide what types "your" json can store. If only int - write a parser, if strings - add functionality for them too. But for classes, you already need a full-fledged js engine. Well, or a compiler-interpreter. It seems to me that this is not quite what you are ready for.
PS: Is this https://github.com/cesanta/mjs not suitable for you? Note that even there there are quite a few restrictions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question