Alright, so having this issue when I try to run my application:
Invalid JSON primitive: .
public static void ReloadConfig()
{
if (!File.Exists("config.cfg"))
{
StringBuilder sb = new StringBuilder();
sb.Append("{\r\n");
sb.Append("\"Admins\":[76561198214617172],\r\n");
sb.Append("\"Chatty\":false,\r\n");
sb.Append("}");
File.WriteAllText("config.cfg", sb.ToString());
}
try
{
JavaScriptSerializer jss = new JavaScriptSerializer();
config = jss.Deserialize<Roles>(File.ReadAllText("config.cfg"));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
ReloadConfig();
}
}
And this is how the config looks like when it's generated:
{
"Admins":[76561198214617172],
"Chatty":false,
}
As from my error message I would assume it says I have a space in my config, but I do not have that.
And if that matters I use System.Web.Script.Serialization
.
You have an errant comma in your output after false
:
{
"Admins":[76561198214617172],
"Chatty":false,
}
Should be:
{
"Admins":[76561198214617172],
"Chatty":false
}
You need to remove the comma after false:
{
"Admins":[76561198214617172],
"Chatty":false
}
I used JSONLint to validate your JSON, there are many other online JSON validators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With