Problem: I wanna get the JSON data that I create in a PHP file ( {"2":"1"} ), and then I echo it in that empty PHP file (no html whatsoever, not even header('Content-Type: application/json');), and then I want to use this code for ESP8622 to get that JSON data:
const char* serverName = "XXX Sex - Free Porn Videos at XXX.com";
WiFiClient client;
HTTPClient http;
http.begin(client, serverName);
String payload = "";
payload = http.getString();
JSONVar myObject = JSON.parse(payload);
if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
return;
}else{
Serial.println("YEAH :)!");
}
I´m stuck with:"Parsing input failed!";
Why? the
payload = http.getString();
returns some HTML as there was some header('Content-Type: application/json'); and this is the result:
<!doctype html>
Untitled Document {"2":"1"}As you can see there is that garbage HTML and the JSON data is after the closing tag yet the PHP file has NO html at all. If I include the header('Content-Type: application/json') in my PHP file then I CAN see that extra HTML in the page as the String created with http.getString() is showing; but there's not need for that extra info, I just need a blank PHP file with json data: {"2":"1"}.
Clean this HTML up isn't the job of JSON.parse(payload);?
How can I just extract the JSON part ({"2":"1"}) from the resulted String from http.getString();?
I'm using these libraries.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <Arduino_JSON.h>
#include <ESP8266WiFiMulti.h>