how to assign Serial text as variable

hi, I tried to read the last data from the private channel in thingspeak here is my nodemcu code.

/**
* BasicHTTPClient.ino
*
* Created on: 24.05.2015
*
*/
#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;
String data="";
String sensor1="";
String sensor2="";
String sensor3="";

void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();

for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...", t);
USE_SERIAL.flush();
delay(1000);
}

WiFiMulti.addAP("amir", "amirzahidin");

}

void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {

HTTPClient http;

USE_SERIAL.print("[HTTP] begin...");
// configure traged server and url
// get the entry_id from Thingspeak from the ThingHTTP TweetControl
http.begin("api.thingspeak.com", 80, "/channels/422084/fields/1.json?api_key=V4CZPJIO1IABBES4&results=2"); //HTTP

USE_SERIAL.print("[HTTP] GET...");
// start connection and send HTTP header
int httpCode = http.GET();

// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
//USE_SERIAL.printf("[HTTP] GET... code: %d", httpCode);

// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
// Print the string value from Thingspeak
USE_SERIAL.println(payload);
// Convert string to integer so that we can utilise the number
int number_tweets = payload.toInt();
//USE_SERIAL.println(2*number_tweets);
 


}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s", http.errorToString(httpCode).c_str());
}

http.end();
}
  
 

delay(10000);
}

this is the serial monitor display.I want to assign the value of 24 as a variable so that I can make the next action.Anyone, please help me.I really appreciate it

[HTTP] begin...[HTTP] GET...{"channel":{"id":422084,"name":"temperature and humidity","latitude":"0.0","longitude":"0.0","field1":"temperature (*C)","field2":"humidity(H)","created_at":"2018-02-08T01:38:56Z","updated_at":"2018-02-08T09:45:17Z","last_entry_id":62},"feeds":[{"created_at":"2018-02-08T09:45:01Z","entry_id":61,"field1":"24"},{"created_at":"2018-02-08T09:45:17Z","entry_id":62,"field1":"24"}]}

I want to assign the value of 24 as a variable so that I can make the next action.Anyone, please help me.I really appreciate it

You don’t yet have the value 24 to assign to a variable.

What you have is poor output, that could easily be improved by using USE_SERIAL.println() more often, rather than USE_SERIAL.print().

It could also be improved by printing prefixes, so one can easily tell what was printed.

Right now, I’d have to guess that {“channel”:{“id”:4 ":“24”}]} was printed because you USE_SERIAL.print()ed payload.

If that was the case, you now need to google ArduinoJSON to learn how to parse json data.

/**
* BasicHTTPClient.ino
*
* Created on: 24.05.2015
*
*/
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;


void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();

for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...", t);
USE_SERIAL.flush();
delay(1000);
}

WiFiMulti.addAP("PHN-AP", "PHN@wifi");
//StaticJsonBuffer<200> jsonBuffer;
//JsonObject& root = jsonBuffer.parseObject(json);
char json[] = "";
//StaticJsonBuffer<200> jsonBuffer;

/* if (!root.success()) {
    Serial.println("parseObject() failed");
    return;
  }*/
 
  //USE_SERIAL.println(longitude, 6);

}

void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {

HTTPClient http;

USE_SERIAL.print("[HTTP] begin...");
// configure traged server and url
// get the entry_id from Thingspeak from the ThingHTTP TweetControl
http.begin("api.thingspeak.com", 80, "/channels/422084/fields/1.json?api_key=V4CZPJIO1IABBES4&results=2"); //HTTP

USE_SERIAL.print("[HTTP] GET...");
// start connection and send HTTP header
int httpCode = http.GET();

// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
//USE_SERIAL.printf("[HTTP] GET... code: %d", httpCode);

// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
// Print the string value from Thingspeak
USE_SERIAL.print(payload);
  // Step 6
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
DynamicJsonBuffer jsonBuffer(capacity);
JsonObject& root = jsonBuffer.parseObject(payload);
 const char* sensor = root["field1"];
 USE_SERIAL.println(sensor);
 /* long time = root["time"];
  double latitude = root["data"][0];
  double longitude = root["data"][1];*/
  


// Convert string to integer so that we can utilise the number
int number_tweets = payload.toInt();
//USE_SERIAL.println(2*number_tweets);
 

}
 
  

} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s", http.errorToString(httpCode).c_str());
}

http.end();

}

  // Step 6
//

 

delay(10000);
}

I change the coding but no output display on serial.
can you help me to figure out why?
thank you so much.

The parse example in Serial Input Basics may give you some ideas.

...R

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();

Why are you pissing away time and effort writing 3 blank lines? If NOTHING is appearing in the Serial Monitor app, give it something printable to print!

char json[] = "";

The compiler counted the number of initializers, and sized the array appropriately. Just what good is an array that can hold just the NULL terminator?