Don't think so. Now i get an error:
class HTTPClient' has no member named 'available'
My mistake... I think this is part of the "Bridge" system. GACK. Very String-class oriented. The readString method is part of the original Stream class, so I though HTTPClient was derived from it.
You could either:
-
use the String class functions to search for "temp", then look for the next quoted value string. Parse the value string as a float. This is the least efficient, and the most susceptible to a variety of String dangers.
-
use a JSON library to parse the info.c_str(). Then access the resulting structure. This is the most complicated, but it might be worth it if you access a lot of the JSON data.
-
use C string functions to scan the info.c_str(). This is most efficient.
Personally, I would use the last approach. This is what PaulS was suggesting, with the exception that the info can only be obtained as a String. You can use the C string (char array) functions on the info.c_str() array:
const char JSON[] = R"jsonString(
{ "liveweer": [{"plaats": "Amsterdam", "temp": "7.3", "gtemp": "5.3", "samenv": "Geheel bewolkt", "lv": "99", "windr": "West", "windms": "3", "winds": "2", "windk": "5.8", "windkmh": "10.8", "luchtd": "1032.8", "ldmmhg": "775", "dauwp": "7", "zicht": "2", "verw": "Bewolkt en nevelig of mistig met plaatselijk (mot)regen.", "sup": "08:45", "sunder": "16:31", "image": "bewolkt", "d0weer": "bewolkt", "d0tmax": "9", "d0tmin": "6", "d0windk": "2", "d0windknp": "4", "d0windms": "2", "d0windkmh": "7", "d0windr": "267", "d0neerslag": "13", "d0zon": "0", "d1weer": "halfbewolkt", "d1tmax": "9", "d1tmin": "7", "d1windk": "2", "d1windknp": "", "d1windms": "", "d1windkmh": "", "d1windr": "W", "d1neerslag": "60", "d1zon": "10", "d2weer": "halfbewolkt", "d2tmax": "8", "d2tmin": "5", "d2windk": "3", "d2windknp": "", "d2windms": "", "d2windkmh": "", "d2windr": "W", "d2neerslag": "40", "d2zon": "10", "alarm": "0"}]}
)jsonString";
void setup()
{
Serial.begin( 9600 );
String info( JSON );
Serial.println( info.c_str() );
const char TEMP_NAME[] = "\"temp\""; // note embedded double quotes
// Use the strstr functuon to look for the key
char *tempPtr = strstr( info.c_str(), TEMP_NAME );
// If the name was found, get the value
if (tempPtr != nullptr) {
// Use the strchr function to look for the colon
char *valuePtr = strchr( tempPtr, ':' );
if (valuePtr != nullptr) {
valuePtr++; // step over the colon
valuePtr = strchr( valuePtr, '\"' ); // look for the starting double quote
if (valuePtr != nullptr) {
valuePtr++; // step over the starting double quote
// Use the atof function parse a float value from
// what follows (stops at the ending double quote).
float value = atof( valuePtr );
Serial.println( value );
} else {
Serial.println( "no value \"" );
}
} else {
Serial.println( "no :" );
}
} else {
Serial.print( "no " );
Serial.println( TEMP_NAME );
}
}
void loop() {}