Using the webhook, I receive a response from my request. The JSON response that I receive is as follows:
{
"value" : [ {
"Datastreams" : [ ],
"Locations" : [ {
"name" : "Place Name",
"description" : "Somewhere in the world",
"@iot.id" : 53750
} ],
"@iot.id" : 53610
} ]
}
This is the script I used to parse the JSON. data being the JSON response from the webhook.
JSONValue outerObj = JSONValue::parseCopy(data);
JSONObjectIterator iter(outerObj);
while(iter.next()) {
bool isArray = iter.value().isArray();
String x = String::format("{\"val\":%s}", isArray ? "true" : "false");
//Particle.publish("CheckingLoop", x, PRIVATE);
JSONArrayIterator iter2(iter.value());
while(iter2.next()){
JSONObjectIterator iter3(iter2.value());
while(iter3.next()){
if(iter3.name() == id){
int id = iter3.value().toInt();
String x = String::format("{\"val\":%d}", id);
Particle.publish("CheckingLoop", x, PRIVATE);
}
}
}
}
However, if I hardcode this response onto my script as shown in the script below, the script will work and is able to parse the data.
String data = String::format("{\"value\" : [ {\"Datastreams\" : [ ],\"Locations\" : [ {\"name\" : \"Place Name\", \"description\" : \"Somewhere in the world\",\"@iot.id\" : 53750} ], \"@iot.id\" : 53610}]}");
So I have tried to convert the const char data into a String data like the script below, the result i get when I published the converted string is incomplete as shown below:
String newData= String::format(data);
tastreams" : [ ],
"Locations" : [ {
"name" : "Place Name",
"description" : "Somewhere in the world",
"@iot.id" : 53750
} ],
"@iot.id" : 53610
} ]
}"@iot.id" : 53610
} ]
}
I cannot really figure out what is happening. It seems like the parsing script is working but just not with the const char data that is coming in from the my request webhook. What seems to be the issue here? Thanks.