Aleks Kpur Aleks Kpur - 8 months ago 37
JSON Question

C# Adding string into listview, causes error?

So I have an piece of code here:

dynamic getPoints = JsonConvert.DeserializeObject<dynamic>(Profile.Profile.Currency.ToString());
var Points = getPoints[1].amount;
addItems(Username, Password, Points);

addItems Void

info.Text = Username;


So after I call this & it tries to do addItems, then this error appears:

The best overloaded method match for ProgramTest.Form1.addItems(string, string string) has some invalid arguments.

How could I solve this issue?


AddItems() doesn't take a dynamic. Solution: don't use dynamic and instead properly convert your JSON data into real types. Use JToken.Parse(). For example:

var json = JArray.Parse(Profile.Profile.Currency.ToString());
var Points = json[1].Value<string>("amount");