zoukankan      html  css  js  c++  java
  • csharp_ToJson的正确写法

    网上搜的,但有问题,已经改好。。。现在这个是正确的

            public static string ToJson(DataTable dt, string jsonName)
            {
                StringBuilder Json = new StringBuilder();
                if (string.IsNullOrEmpty(jsonName))
                    jsonName = dt.TableName;
                Json.Append("{"" + jsonName + "":[");
                //Json.Append("{"" + jsonName + "":");
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Json.Append("{");
                        for (int j = 0; j < dt.Columns.Count; j++)
                        {
                            Type type = dt.Rows[i][j].GetType();
                            if (type.Name.ToString() == "Int32")
                            {
                                Json.Append(""" + dt.Columns[j].ColumnName.ToString() + "":" + String.Format(dt.Rows[i][j].ToString(), type));
                            }
                            else
                            {
                                Json.Append(""" + dt.Columns[j].ColumnName.ToString() + "":"" + String.Format(dt.Rows[i][j].ToString(), type));
                            }
                            if (j < dt.Columns.Count - 1)
                            {
                                if (type.Name.ToString() == "Int32")
                                {
                                    Json.Append(",");
                                }
                                else
                                {
                                    Json.Append("",");
                                }
                            }
                        }
                        Json.Append(""}");
                        if (i < dt.Rows.Count - 1)
                        {
                            Json.Append(",");
                        }
                    }
                }
                Json.Append("]}");
                //Json.Append("}");
                return Json.ToString();
            }
        }
    }

  • 相关阅读:
    Tensorflow入门:Linear Regression
    日语动词变形总结
    序列模型第二周作业2:Emojify!
    序列模型第二周作业1:Operations on word vectors
    序列模型第一周作业3: Improvise a Jazz Solo with an LSTM Network
    序列模型第一周作业2: Character level language model
    序列模型第一周作业1: Building your Recurrent Neural Network
    Bidirectional RNN (BRNN)
    Long Short term memory unit(LSTM)
    propertyGrid使用
  • 原文地址:https://www.cnblogs.com/weiryang/p/3208155.html
Copyright © 2011-2022 走看看