C#转换json

<textarea cols="50" rows="15" name="code" class="c-sharp"> public static string CreateJsonByDataTable(DataTable dt) { StringBuilder jsonString = new StringBuilder(); if (dt != null &amp;&amp; dt.Rows.Count &gt; 0) { jsonString.Append("["); for (int i = 0; i &lt; dt.Rows.Count; i++) { jsonString.Append("{"); for (int j = 0; j &lt; dt.Columns.Count; j++) { if (j &lt; dt.Columns.Count - 1) { jsonString.Append("/"" + dt.Columns[j].ColumnName.ToString() + "/":" + "/"" + dt.Rows[i][j].ToString() + "/","); } else if (j == dt.Columns.Count - 1) { jsonString.Append("/"" + dt.Columns[j].ColumnName.ToString() + "/":" + "/"" + dt.Rows[i][j].ToString() + "/""); } } if (i == dt.Rows.Count - 1) { jsonString.Append("}"); } else { jsonString.Append("},"); } } jsonString.Append("]"); return jsonString.ToString(); } else { return string.Empty; } }</textarea>

你可能感兴趣的:(C#转换json)