Hello @Given Mnisi,
I tested the code with Visual Studio. It test JSON for me while debugging:
It seems the doubles come with decimal 'comma' instead of decimal point:
{"vehicle_id": 7941, "timestamp": "2023-10-19 19:25:17", "latitude": -45,8807284588388, "longitude": 90,01136751036734}
Note: I live in The Netherlands, so this could be a regional thing.
I tested by turning lat and long into integers:
var latitude = (int) random.NextDouble() * 180 - 90;
var longitude = (int) random.NextDouble() * 360 - 180;
It's probably the string concatenation giving the problem.
A better way to work with JSON messages is Serialization and Deserialization.
Here is an example:
using Newtonsoft.Json;
internal class Program
{
static void Main(string[] args)
{
Random random = new Random();
var message = new Message
{
vehicleId = 1,
timestamp = DateTime.Now,
latitude = random.NextDouble() * 180 - 90,
longitude = random.NextDouble() * 360 - 180
};
var data = JsonConvert.SerializeObject(message);
Console.WriteLine(data);
var message2 = JsonConvert.DeserializeObject<Message>(data);
}
}
public class Message
{
public int vehicleId { get; set; }
public DateTime timestamp { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
}
The data property is what you will need in your application. Remove that string concatenation.
Regarding Azure Stream Analytics giving the issue.
It could be you will have some issues with the corrupt messages still in the pipeline between EventHub and Azure Stream Analytics due to the retention time. Eventually these will be removed.
If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.