I am facing issue with deserializing json which contains value with special character (i.e. quote).
I am loading json from file (its adaptive card).
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "<TitleValue>",
"wrap": true,
"size": "Large"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://adaptivecards.io/content/cats/1.png",
"size": "Small"
}
]
}
]
},
{
"type": "TextBlock",
"text": "<BodyValue>",
"wrap": true,
"size": "Medium"
}
],
"minHeight": "206px"
}
Then I am replacing two placeholders with strings i got from the chatbot and generate adaptive card attachment.
public static Attachment CreateNoteCardAttachment(string noteTitle, string noteBody)
{
// combine path for cross platform support
var paths = new[] { ".", "Resources", "NoteAdaptiveCard.txt" };
var noteCardJson = File.ReadAllText(Path.Combine(paths));
noteCardJson = noteCardJson.Replace("<TitleValue>", noteTitle);
noteCardJson = noteCardJson.Replace("<BodyValue>", noteBody);
var noteCardAttachment = new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(noteCardJson),
};
return noteCardAttachment;
}
The issue occurs, when the string contains double quote. Then JsonConvert.DeserializeObject
returns exception: After parsing a value an unexpected character was encountered...
I am not able to figure out how to parse/deserialise the input strings I replace in order to allow JsonConvert to successfully deserialize the entire adaptive card.