Problem with StringBuilder and JSON

I am trying to execute this code in C # .NET to turn an SQL table into a string with proper JSON;

json.AppendFormat("Places: [{{\"AvgDate\": \"{0}\"},\"MarkerID\": \"{1}\"}]", reader["AvgDate"], reader["MarkerID"]);

However, it will not allow me to use comma separation between indices {0} and {1}. The following works great:

json.AppendFormat("Places: [{{\"AvgDate\": \"{0}\"}]", reader["AvgDate"], reader["MarkerID"]);

What am I doing wrong?

+3
source share
2 answers

Closing braces should also be doubled in the format string:

json.AppendFormat("Places: [{{\"AvgDate\": \"{0}\"}},\"MarkerID\": \"{1}\"}]", reader["AvgDate"], reader["MarkerID"]);

Pay attention to }}after AvgDate:

+2
source

You are missing there) ... not sure if this is your exact problem, but the problem ...

+2
source

Source: https://habr.com/ru/post/1733975/


All Articles