Failing to Parse json?

So I am trying to modify another’s code to call from a different api. The problem I am having is that i cannot get a success to happen when parsing the json. I have tried it as an array and an object.

I have noticed that because of the way this is iterating through the char c = client.read(); my variable body ends up with the number 436 on a line before the json and its followed by the number on a new line 0. Could this be what is causing the parse to fail? If it is, how do I skip them and not load then into body?

Sorry noob stuff I know =/

This is what I get when I Serial.print(body):

436
{“donations”:[{“id”:106111292,“created_at”:“2018-07-11 00:36:39”,“amount”:“1.0000000000”,“currency”:“USD”,“amount_label”:"$1.00",“donator”:{“id”:“da39a3ee5e6b4b0d3255bfef95601890afd80709”,“name”:“christopher”},“message”:“test money”},{“id”:106116667,“created_at”:“2018-07-11 03:55:54”,“amount”:“1.0000000000”,“currency”:“USD”,“amount_label”:"$1.00",“donator”:{“id”:“da39a3ee5e6b4b0d3255bfef95601890afd80709”,“name”:“ChrisGolden”},“message”:""},{“id”:106119515,“created_at”:“2018-07-11 06:01:58”,“amount”:“1.0000000000”,“currency”:“USD”,“amount_label”:"$1.00",“donator”:{“id”:“da39a3ee5e6b4b0d3255bfef95601890afd80709”,“name”:“ChrisGolden”},“message”:""},{“id”:106120305,“created_at”:“2018-07-11 06:49:23”,“amount”:“1.0000000000”,“currency”:“USD”,“amount_label”:"$1.00",“donator”:{“id”:“da39a3ee5e6b4b0d3255bfef95601890afd80709”,“name”:“Withak”},“message”:""},{“id”:106122028,“created_at”:“2018-07-11 08:58:49”,“amount”:“1.0000000000”,“currency”:“USD”,“amount_label”:"$1.00",“donator”:{“id”:“da39a3ee5e6b4b0d3255bfef95601890afd80709”,“name”:“PortlandAndy”},“message”:“Shocker”}]}
0

#include <ArduinoJson.h>
#include <ESP8266WiFi.h>

//Include the SSL client
#include <WiFiClientSecure.h>

char ssid[] = "xxxx";       // your network SSID (name)
char password[] = "xxxxxx";  // your network key

//Add a SSL client
WiFiClientSecure client;



long checkRedditDueTime;
int checkRedditDelay = 60000; // 60 x 1000 (1 minute)

void setup() {

 Serial.begin(115200);

 // Set WiFi to station mode and disconnect from an AP if it was Previously
 // connected
 WiFi.mode(WIFI_STA);
 WiFi.disconnect();
 delay(100);

 // Attempt to connect to Wifi network:
 Serial.print("Connecting Wifi: ");
 Serial.println(ssid);
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   Serial.print(".");
   delay(500);
 }
 Serial.println("");
 Serial.println("WiFi connected");
 Serial.println("IP address: ");
 IPAddress ip = WiFi.localIP();
 Serial.println(ip);

}

String getDonos() {
 String title = "";
 String headers = "";
 String body = "";
 bool finishedHeaders = false;
 bool currentLineIsBlank = true;
 bool gotResponse = false;
 long now;

 char host[] = "streamlabs.com";

 if (client.connect(host, 443)) {
   Serial.println("connected");
   
   String URL = "/api/donations?access_token=xxxxxxxxxxxxxx";

   Serial.println(URL);
   
   client.println("GET " + URL + " HTTP/1.1");
   client.print("Host: "); client.println(host);
   client.println("User-Agent: ");
   client.println("");

   now = millis();
   // checking the timeout
   while (millis() - now < 1500) {
     while (client.available()) {
       char c = client.read();
       //Serial.print(c);

       if (finishedHeaders) {
         body=body+c;
       } else {
         if (currentLineIsBlank && c == '\n') {
           finishedHeaders = true;
         }
         else {
           headers = headers + c;
         }
       }

       if (c == '\n' ) {
         currentLineIsBlank = true;
       }else if (c != '\r') {
         currentLineIsBlank = false;
       }

       //marking we got a response
       gotResponse = true;

     }
     if (gotResponse) {
       Serial.print("I got a response!");
       Serial.print('\n');

       DynamicJsonBuffer jsonBuffer;
       JsonArray& root = jsonBuffer.parseArray(body);
       if (root.success()) {
         Serial.print ("YAY!!!");
         //if (root.containsKey("donations")) {
           //JsonObject& post = root["donations"]["children"][0];
           //if (post.containsKey("data")) { 
             //title = post["data"]["title"].as<String>();
           //}
         //} 
       } else {
         Serial.println("failed to parse JSON");
       }

       break;
     }
   }
 }

 Serial.println(body);
 
 return body;
}

void loop() {
 long now = millis();
 if(now >= checkRedditDueTime) {
   Serial.println("---------");
   String body = getDonos();
   if(body != "") {
    // Serial.println("Most recent post on /r/" + subredditName);
     //Serial.println(body);
   } else {
    Serial.println("Error getting title."); 
   }
   Serial.println("---------");
   checkRedditDueTime = now + checkRedditDelay;
 }
}

Could this be what is causing the parse to fail?

Most probably yes, because that isn't JSON.

You should check the server output to see if that's actually the output the server returns or if you just fail to parse the response correctly.

You shouldn't tell the server that you're using HTTP/1.1 if you actually don't.

If you take the example you have in #1 (without the 436 & 0 prefix/postfix) and post it into here you get code examples on how to read the data.

{"donations":[{"id":106111292,"created_at":"2018-07-11 00:36:39","amount":"1.0000000000","currency":"USD","amount_label":"$1.00","donator":{"id":"da39a3ee5e6b4b0d3255bfef95601890afd80709","name":"christopher"},"message":"test money"},{"id":106116667,"created_at":"2018-07-11 03:55:54","amount":"1.0000000000","currency":"USD","amount_label":"$1.00","donator":{"id":"da39a3ee5e6b4b0d3255bfef95601890afd80709","name":"ChrisGolden"},"message":""},{"id":106119515,"created_at":"2018-07-11 06:01:58","amount":"1.0000000000","currency":"USD","amount_label":"$1.00","donator":{"id":"da39a3ee5e6b4b0d3255bfef95601890afd80709","name":"ChrisGolden"},"message":""},{"id":106120305,"created_at":"2018-07-11 06:49:23","amount":"1.0000000000","currency":"USD","amount_label":"$1.00","donator":{"id":"da39a3ee5e6b4b0d3255bfef95601890afd80709","name":"Withak"},"message":""},{"id":106122028,"created_at":"2018-07-11 08:58:49","amount":"1.0000000000","currency":"USD","amount_label":"$1.00","donator":{"id":"da39a3ee5e6b4b0d3255bfef95601890afd80709","name":"PortlandAndy"},"message":"Shocker"}]}