I got the following error while trying to add an object of type class to a JArray .
Could not determine JSON object type for type "Class"
Here is the code I'm using:
private dynamic _JArray = null
private JArray NArray(Repository repository)
{
_JArray = new JArray();
string[] amounts = repository.Amounts.Split('|');
for (int i = 0; i <= amounts.Length; i++)
{
_JArray.Add(
new AmountModel
{
Amounts = amounts[i],
});
}
return _JArray;
}
public class AmountModel
{
public string Amounts;
}
And when I call the program, I call it like this:
_JArray = NArray(repository);
Console.WriteLine(JsonConvert.SerializeObject(_JArray));
How can I convert an AmountModel (class) inside _JArray (JArray) so that the system recognizes a JSON object?
I really liked your answer.
Thank.
source
share