4

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 won't let me use the comma separation between the {0} and {1} indexes. The following works fine;

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

What am I doing wrong?

2 Answers 2

3

Closing braces must also be doubled in a format string:

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

Notice the }} after AvgDate:

Sign up to request clarification or add additional context in comments.

Comments

2

You've got a missing } in there...not sure if that's your exact problem, but its a problem....

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.