Trouble Parsing Json Object

Hi!

I am trying to parse my Json object, however, the values that are being returned are 0. Here is my code:

float price = 100.0;
float change = 100.0;

       WiFiClient client;
      HTTPClient http;
      String command = "http://passiveincomeconsultingllc.com/getStockPrices.php?stock=" + stockArguments[i];
      http.begin(client,command);
       int httpCode = http.GET();


  
 
    if (httpCode > 0) {  //Check the returning code
        String payload = http.getString();
        JsonObject& root = jsonBuffer.parseObject(payload );
     
     price  = root["price"];
     change = root["percent_change"];

When I display the "payload" I get

{"price":500,"percent_change":5}

Which is correct, but When I try setting the price and percent_change variable in my Arduino code it returns 0.0?

Is it an issue with declaration of variables?

Can you post the entire sketch?

I can't but why would that be needed? its just this one function that is giving issues.

It gives us a chance to reproduce the problem and fix it.

You can also post a minimal sketch that has the same problem.

It's not clear to me from context what JSON library you are using. If it was the ArduinoJSON V6 library you might need something like:

     price  = root["price"].as<int>();
     change = root["percent_change"].as<int>();

Check your library documentation to see how to get a number from your JSON element.

@aj954, your topic has been moved to a more suitable location on the forum as this has nothing to do with Avrdude, stk500 or Bootloader.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.