接收到的數據工作,我接收到的數據:怎樣才能從Azure的物聯網中心
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