16-08-19 03:31 PM
please help a doomed soul. I don't understand how to cast each part of the nested json into a datatable.
I tried creating the public classes using the tool provided at json2csharp.com, and then point to them and write to the data table.
I also tried by not creating the classes and just convert json directly to the data table.
With classes:
DataSet ds = JObject.Parse(json_txt)['recognitionResults'].ToObject();
Without classes:
DataTable dt = (DataTable)JsonConvert.DeserializeObject(json_txt, (typeof(DataTable)));
Classes:
public class Word
{
public List<double> boundingBox { get; set; }
public string text { get; set; }
public string confidence { get; set; }
}
public class Line
{
public List<double> boundingBox { get; set; }
public string text { get; set; }
public List<Word> words { get; set; }
}
public class RecognitionResult
{
public int page { get; set; }
public double clockwiseOrientation { get; set; }
public double width { get; set; }
public double height { get; set; }
public string unit { get; set; }
public List<Line> lines { get; set; }
}
public class RootObject
{
public string status { get; set; }
public List<RecognitionResult> recognitionResults { get; set; }
}
JSON txt:
pastebin.com/yBVrLveq
For context:
I used the Microsoft Computer Vision API to recognize text from a PDF.
If is not possible to map each property of the json file into the datatable, it would be fine to have a table like:
'page 0' : 'lines' 'page 1' : 'lines'
Each set of 'lines' contains a variable number of lines. That's what I mean by nested.
--------------------------------------------------Answered! Go to Answer.
20-04-20 10:37 PM
20-04-20 10:37 PM