Let's say the GET response is a flat string containing a large .json file with all the commas and curly brackets. The idea is to read it byte-by-byte, and instead of storing it, just find the key you need and extract its value.
HTTPClient http;
http.begin("http://data.nba.net/data/10s/prod/v1/20190223/scoreboard.json");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK)
Serial.println(getValue(http, "97.5 FM", 3, 4));
HTTPClient http;
http.begin("http://data.nba.net/data/10s/prod/v1/20190223/scoreboard.json");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK)
Serial.println(getValue(http, "97.5 FM", 3, 4));
whereWhere the getValue() function is defined as follows:
String getValue(HTTPClient &http, String key, int skip, int get) {
bool found = false, look = false;
int ind = 0;
String ret_str = "";
int len = http.getSize();
char char_buff[1];
WiFiClient * stream = http.getStreamPtr();
while (http.connected() && (len > 0 || len == -1)) {
size_t size = stream->available();
if (size) {
int c = stream->readBytes(char_buff, ((size > sizeof(char_buff)) ? sizeof(char_buff) : size));
if (len > 0)
len -= c;
if (found) {
if (skip == 0) {
ret_str += char_buff[0];
get --;
} else
skip --;
if (get <= 0)
break;
}
else if ((!look) && (char_buff[0] == key[0])) {
look = true;
ind = 1;
} else if (look && (char_buff[0] == key[ind])) {
ind ++;
if (ind == key.length()) found = true;
} else if (look && (char_buff[0] != key[ind])) {
ind = 0;
look = false;
}
}
}
return ret_str;
}
String getValue(HTTPClient &http, String key, int skip, int get) {
bool found = false, look = false;
int ind = 0;
String ret_str = "";
int len = http.getSize();
char char_buff[1];
WiFiClient * stream = http.getStreamPtr();
while (http.connected() && (len > 0 || len == -1)) {
size_t size = stream->available();
if (size) {
int c = stream->readBytes(char_buff, ((size > sizeof(char_buff)) ? sizeof(char_buff) : size));
if (len > 0)
len -= c;
if (found) {
if (skip == 0) {
ret_str += char_buff[0];
get --;
} else
skip --;
if (get <= 0)
break;
}
else if ((!look) && (char_buff[0] == key[0])) {
look = true;
ind = 1;
} else if (look && (char_buff[0] == key[ind])) {
ind ++;
if (ind == key.length()) found = true;
} else if (look && (char_buff[0] != key[ind])) {
ind = 0;
look = false;
}
}
}
return ret_str;
}
There is probably (i.e., most likely) a better way of doing this, but this approach works and it's pretty fast, so...