txt to string

 /*I want all the information
     to read sd and drop in 
    string and drop in json 
    and print json in the serial 
    monitor through it.*/

    // But at the output it gives 1-


    //Can you help me? I'm in a hurry

    //I don't know how to put a variable or txt in 
//string, and I don't know how to add it to my code. –

        #include <mySD.h>

        File root;

        #include <ArduinoJson.h>

        String b {


          root = SD.open("1.txt");
              if (root) {
              while (root.available()) {
      return (String (root.read()));

         }   
          root.close();
        }
        }

        String mydate = b;

        String  json = "{\"sensor\" : \""+mydate+"\"}";

        void setup() {
        Serial.begin(115200);
          while (!Serial) continue;
    Serial.print("Initializing SD card...");
  /* initialize SD library with Soft SPI pins, if using Hard SPI replace with this SD.begin()*/
  if (!SD.begin(5)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  //...................................................
  /* Begin at the root "/" */
  root = SD.open("/");
  if (root) {    
    printDirectory(root, 0);
    root.close();
  } else {
    Serial.println("error opening test.txt");
  }

          StaticJsonDocument<2000> doc;
          DeserializationError error = deserializeJson(doc, json);
           if (error) {
            Serial.print(F("deserializeJson() failed: "));
            Serial.println(error.c_str());
            return;
          }
          long sensor = doc["sensor"];
          Serial.println(sensor);
    voide loop(){
       }]

Can you help me? I'm in a hurry

In that case, no. It won't play out well. Thanks for using code tags though! It would be better if you moved your request text out of the code...

(deleted)

I want all the information
     to read sd and drop in
    string and drop in json
    and print json in the serial
    monitor through it


    // But at the output it gives 1-


    //Can you help me? I'm in a hurry

    //I don't know how to put a variable or txt in
//string, and I don't know how to add it to my code. -1

#include <mySD.h>

File root;

#include <ArduinoJson.h>

String b {

root = SD.open("1.txt");
if (root) {
while (root.available()) {
return (String (root.read()));

}
root.close();
}
}

String mydate = b;

String json = "{"sensor" : ""+mydate+""}";

void setup() {
Serial.begin(115200);
while (!Serial) continue;
Serial.print("Initializing SD card...");
/* initialize SD library with Soft SPI pins, if using Hard SPI replace with this SD.begin()*/
if (!SD.begin(5)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

//...................................................
/* Begin at the root "/" */
root = SD.open("/");
if (root) {
printDirectory(root, 0);
root.close();
} else {
Serial.println("error opening test.txt");
}

StaticJsonDocument<2000> doc;
DeserializationError error = deserializeJson(doc, json);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
long sensor = doc["sensor"];
Serial.println(sensor);
voide loop(){
}]

I want all the information
to read sd and drop in
string and drop in json
and print json in the serial
monitor through it

// But at the output it gives 1-

//Can you help me? I'm in a hurry

//I don't know how to put a variable or txt in
//string, and I don't know how to add it to my code. -1

#include <mySD.h>

File root;

#include <ArduinoJson.h>

String b {

root = SD.open("1.txt");
if (root) {
while (root.available()) {
return (String (root.read()));

}
root.close();
}
}

String mydate = b;

String json = "{"sensor" : ""+mydate+""}";

void setup() {
Serial.begin(115200);
while (!Serial) continue;
Serial.print("Initializing SD card...");
/* initialize SD library with Soft SPI pins, if using Hard SPI replace with this SD.begin()*/
if (!SD.begin(5)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

//...................................................
/* Begin at the root "/" */
root = SD.open("/");
if (root) {
printDirectory(root, 0);
root.close();
} else {
Serial.println("error opening test.txt");
}

StaticJsonDocument<2000> doc;
DeserializationError error = deserializeJson(doc, json);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
long sensor = doc["sensor"];
Serial.println(sensor);
voide loop(){
}

hosein12s:
I want all the information
to read sd and drop in
string and drop in json
and print json in the serial
monitor through it

// But at the output it gives 1-

//Can you help me? I'm in a hurry

Sorry, free forums work on their own time...

//I don't know how to put a variable or txt in
//string, and I don't know how to add it to my code. -1

And you don't know how to properly post your code so people can more easily help you.
I know you are in a hurry, but take the time to read the sticky post at the top of the forum about how to post your code with code tags. It will help people help you.

I want all the information
    to read sd and drop in
   string and drop in json
   and print json in the serial
   monitor through it


   // But at the output it gives 1-


   //Can you help me?

   //I don't know how to put a variable or txt in
//string, and I don't know how to add it to my code. -1
      #include <mySD.h>

      File root;

      #include <ArduinoJson.h>

      String b {


        root = SD.open("1.txt");
            if (root) {
            while (root.available()) {
    return (String (root.read()));

       }  
        root.close();
      }
      }

      String mydate = b;

      String  json = "{\"sensor\" : \""+mydate+"\"}";

      void setup() {
      Serial.begin(115200);
        while (!Serial) continue;
  Serial.print("Initializing SD card...");
/* initialize SD library with Soft SPI pins, if using Hard SPI replace with this SD.begin()*/
if (!SD.begin(5)) {
  Serial.println("initialization failed!");
  return;
}
Serial.println("initialization done.");

//...................................................
/* Begin at the root "/" */
root = SD.open("/");
if (root) {    
  printDirectory(root, 0);
  root.close();
} else {
  Serial.println("error opening test.txt");
}

        StaticJsonDocument<2000> doc;
        DeserializationError error = deserializeJson(doc, json);
         if (error) {
          Serial.print(F("deserializeJson() failed: "));
          Serial.println(error.c_str());
          return;
        }
        long sensor = doc["sensor"];
        Serial.println(sensor);
  voide loop(){
     }

(deleted)

@hosein12s

you now have a 48 hour ban besides the banning of your sock puppet account.
Take that time to CAREFULLY got through the links below.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Future infraction will result in longer or PERMANENT bans.