开发者

Problem with StringBuilder and JSON

开发者 https://www.devze.com 2022-12-20 19:05 出处:网络
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[

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 wo开发者_如何学Pythonn'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?


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:


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

0

精彩评论

暂无评论...
验证码 换一张
取 消