I am currently required to create a script that needs to update the metadata of the qna pairs in QnA Maker by matching the questions i have in an excel file. i am currently following the REST API guides:
https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/csharp
i have retrieved the qna pairs from QnA Maker already but since it returned a string value of all the qna information, i need to convert it to JSON and match it against my List of QnA Objects i have retrieved from my excel files.
public async static Task<string> GetQnAFromQnAMaker()
{
string getmethod = "/knowledgebases/{0}/{1}/qna/";
var method_with_id = String.Format(getmethod, kbid, env);
var uri = host + service + method_with_id;
Console.WriteLine("Calling " + uri + ".");
var response = await Get(uri);
return response;
}
i used NewtonSoft Deserialize object
List<FAQs> qnaMakerFaq = JsonConvert.DeserializeObject<List<FAQs>>(qnaFromQnAMaker.Result);
but i get this error:
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ExcelToQnAMaker.FAQs]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'qnaDocuments', line 2, position 17.'
my returned result string looks something like this...
"{\r\n \"qnaDocuments\": [\r\n {\r\n \"id\": ....
This is my FAQs Class
public class FAQs
{
public List<string> Questions { get; set; }
public string Answers { get; set; }
public string Classification { get; set; }
public string Division { get; set; }
public int Spid { get; set; }
public int Kbid { get; set; }
}
FAQs
do not have any property namedqnaDocuments
which contains an array of data. – vikscool