Skip to content

parsing works sometimes and crashes others #752

Description

@AdamMiltonBarker

Hi guys I am using this with paho c, both installed using VCPKG and used in a C++ console app. I attempting to convert message->payload to json so I can access the elements of the response. This works sometimes but in others I get errors such as:

"parse error - unexpected 's'; expected end of input"

Exactly the same response is work and not working randomly. This is the code which is the on message arrived callback from paho:

int msgarrvd(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
{
	int i;
	const char* payloadptr;

	payloadptr = (const char*)message->payload;
	std::cout << payloadptr;
	std::vector<std::string> v = explode("/", topicName);
	std::string s(payloadptr);
	std::cout << s;
	json data = json::parse(s+'\n');
	std::cout << data["Command"];

	if (v[4]=="Commands") {

	}
	 
	MQTTAsync_freeMessage(&message);
	MQTTAsync_free(topicName);
	return 1;
}

Example response:

{"Sensor":"CCTV","SensorID":130,"Command":"Capture","CommandValue":"Face"}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions