Freigeben über


Logic App: Json serialization issue when receiving message from Service Bus

When parsing message received by logic App from Service, got the error “
InvalidJSON . The 'content' property of actions of type 'ParseJson' must be valid JSON. The provided value '@string3https://schemas.microsoft.com/2003/10/Serialization/�>{ "Field1": "Test1", "Field2": "Test2", "Field3": "Test3" }' cannot be parsed: 'Unexpected character encountered while parsing value: @. Path '', line 0, position 0.'.

We have the additional @string3https://schemas.microsoft.com/2003/10/Serialization/�> serialization information before my actual message content.

Code used to send message to Service bus

var connectionString = @"ConnectionString";

var queueName = "queuename";

 

var client = QueueClient.CreateFromConnectionString(connectionString, queueName);

string jsonmsg = @"{  ""Field1"": ""Test1"",  ""Field2"": ""Test2"",  ""Field3"": ""Test3"" }

var message = new BrokeredMessage(jsonmsg);

 

client.Send(message);

I am formatting the String datatype jsonmsg as a Brokered message sending it to Service bus.

Instead I send the jsonmsg as a stream to the brokered, to resolve the above issue.

var client = QueueClient.CreateFromConnectionString(connectionString, queueName);

string jsonmsg = @"{  ""Field1"": ""Test1"",  ""Field2"": ""Test2"",  ""Field3"": ""Test3"" }";

 

byte[] bytes = Encoding.UTF8.GetBytes(jsonmsg);

MemoryStream stream = new MemoryStream(bytes, writable: false);

var msg = new BrokeredMessage(stream) ;

client.Send(msg);