Reputation: 1031
I have a json file that looks like this:
[
[value1, value2, value3]
[value2, value2, value3]
...
]
I've tried to use both
using (StreamReader r = new StreamReader(HostingEnvironment.MapPath("~/Content/TempData/CapitalSparesBucketsTableData.json")))
{
string json = r.ReadToEnd();
JavascriptSerialzer ser = new JavaScriptSerializer()
var r = ser.Deserialize<ResultList>(json);
}
and
using (StreamReader r = new StreamReader(HostingEnvironment.MapPath("~/Content/TempData/searchData.json")))
{
string json = r.ReadToEnd();
List<SearchResult> searchResults = JsonConvert.DeserializeObject<List<SearchResult>>(json);
}
and I get errors using both methods.
My model looks like this:
public class SearchResults
{
public int TotalRecords { get; set; }
public SearchResult[] Results { get; set; }
}
public class ResultList
{
public SearchResult record;
}
public class SearchResult
{
public SearchResult() { }
public SearchResult(IDataReader reader)
{
DataTable dt = new DataTable();
using (reader)
{
dt.Load(reader);
}
DataRow row = dt.Rows[0];
}
public int Value1 { get; set; }
public int Value2 { get; set; }
public string Value3 { get; set; }
public string Value4 { get; set; }
public string Value5 { get; set; }
public string Value6 { get; set; }
}
Any help would be appreciated.
TIA
Upvotes: 0
Views: 1073
Reputation: 193
Hmm, looks like a Jagged Array. I tried this and it worked with .Net Core 2.2.
var result = JsonConvert.DeserializeObject<IEnumerable<IEnumerable<string>>>("[['value'],['value']]");
Obs.: couldn't find any question that is exactly like this question.
Upvotes: 1