Extracting JSON string from dynamic text

Bot is trying to deserialize text : {“ID:XX”, "Name=“ABC”} but today there is additional text came up while extracting this text.

New text :

Caution:Warning

{“ID:XX”, "Name=“ABC”}

Objective is to extract this text and deserialize. It seems there is no control on text coming before and after this JSON.

I am thinking to add extra test before and after this JSON to manipulate for e.g.
Before{“ID:XX”, "Name=“ABC”}After

What would be best way to always extract this text {“ID:XX”, "Name=“ABC”} at any dynamic text before ‘Before’ and after ‘After’ text.

Regex or Trim Left, Right? Pls share your thoughts to handle such cases.

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"{[\s\S]*}").Value

Regards,

1 Like

Thanks Yoichi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.