Я получаю данные:Как я могу работать с полученными данными из Azure IoT Hub
public void accept(PartitionReceiver receiver)
{
System.out.println("** Created receiver on partition " + partitionId);
try {
while (true) {
Iterable<EventData> receivedEvents = receiver.receive(10).get();
int batchSize = 0;
if (receivedEvents != null)
{
for(EventData receivedEvent: receivedEvents)
{
System.out.println(String.format("| Time: %s", receivedEvent.getSystemProperties().getEnqueuedTime()));
System.out.println(String.format("| Device ID: %s", receivedEvent.getProperties().get("iothub-connection-device-id")));
System.out.println(String.format("| Message Payload: %s", new String(receivedEvent.getBody(), Charset.defaultCharset())));
batchSize++;
}
}
}
} catch (Exception e)
{
System.out.println("Failed to receive messages: " + e.getMessage());
}
}
Здесь я стал названием продукта и цена:
System.out.println(String.format("| Message Payload: %s", new String(receivedEvent.getBody(), Charset.defaultCharset())));
Как я могу взять на себя полезную нагрузку, продукт в String-продукт; и цена в двойную цену ;?
Полезная нагрузка будет json-строкой. Таким образом, вы можете десериализовать соответствующий объект и использовать. – Aravind