JSON转换为DataTable

JsonToDataTable

        private void JsonToDatable(JObject pJObject, DataTable dataTable)
        {
            try
            {
                if (pJObject != null && pJObject.Count != 0)
                {
                    DataRow pRow = dataTable.NewRow();
                    pRow[m_sLoginName] = pJObject["userName"].ToString();
                    pRow[m_sUserName] = pJObject["userName"].ToString();
                    pRow[m_sEMail] = pJObject["email"].ToString();
                    pRow[m_sPhone] = pJObject["tellPhone"].ToString();
                    pRow[m_sAddress] = pJObject["address"].ToString();

                    switch (pJObject["type"].ToString())
                    {
                        case "0":
                            pRow[m_sUserType] = "超级用户";
                            break;
                        case "1":
                            pRow[m_sUserType] = "管路员";
                            break;
                        case "2":
                            pRow[m_sUserType] = "单位管理员";
                            break;
                        case "3":
                            pRow[m_sUserType] = "普通用户";
                            break;
                    }

                    JObject jObject = JObject.Parse(pJObject["orgData"].ToString());
                    string sOrganizition = jObject["name"].ToString();
                    pRow[m_sOrganizition] = sOrganizition;
                    dataTable.Rows.Add(pRow);
                }
            }
            catch { }
        }

你可能感兴趣的:(JSON数据,C#,json,dataTable)