Parsing Json data

Hello! I want parsing json data from http server post. On esp8266 running a http server and sends ir signals, when i make a post request. (php webserver, android phone...) The IR values are stored on the esp8266, but i want replace this method to json data. And not storing any ir commands on esp8266.

Like this: 1. the php webserver makes a curl json post to my esp8266. {command:hex, value:0x1FE48B7} or {command:raw, value:1304, 1188, 494, 1210, 2100, 1206, 1306, 1188, 2144, 1188, 2144, 1188, 472, 1206, 464, 2028, 472, 2020, 492} 2. the esp8266 parsing the json data and send the posted command to the ir diode.

Is that possible?

Thanks!

Is that possible?

Yes most probably

you could use the string tokeniser to extract the integers etc, e.g.

// strtok example - parse tokens into integers

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
    char str[] =" {command:raw, value:1304, 1188,  494, 1210,  2100, 1206,  1306, 1188,  2144, 1188,  2144, 1188,  472, 1206,  464, 2028,  472, 2020,  492}";    // text to tokenise
    char * pch;                     // pointer to tokens
    Serial.print("Splitting string ");
    Serial.print(str);
    Serial.println(" into tokens:");
    pch = strtok (str,":,}{");         // get first token
    while (pch != NULL)
      {
      int x=999;
      Serial.print("string found ");
      Serial.print(pch);          // print it
      x=atoi(pch);                // convert to  integer
      Serial.print("   integer = ");
      Serial.println(x);            // print integer
      pch = strtok (NULL, ":,}{");     // get next token
     }  
}

void loop() {}

wheb run gives

Splitting string  {command:raw, value:1304, 1188,  494, 1210,  2100, 1206,  1306, 1188,  2144, 1188,  2144, 1188,  472, 1206,  464, 2028,  472, 2020,  492} into tokens:
string found     integer = 0
string found command   integer = 0
string found raw   integer = 0
string found  value   integer = 0
string found 1304   integer = 1304
string found  1188   integer = 1188
string found   494   integer = 494
string found  1210   integer = 1210
string found   2100   integer = 2100
string found  1206   integer = 1206
string found   1306   integer = 1306
string found  1188   integer = 1188
string found   2144   integer = 2144
string found  1188   integer = 1188
string found   2144   integer = 2144
string found  1188   integer = 1188
string found   472   integer = 472
string found  1206   integer = 1206
string found   464   integer = 464
string found  2028   integer = 2028
string found   472   integer = 472
string found  2020   integer = 2020
string found   492   integer = 492

the first 3 tokens are not integers hence atoi() returns 0

Thanks!

But, i use rather the args() method. It is simple!

String command1=server.argName(0);
String value1=server.arg(0);
String command2=server.argName(1);
String value2=server.arg(1);