需要帮助在数据网格视图中显示json格式数据 [英] need help to display the json format data in data grid view

查看:140
本文介绍了需要帮助在数据网格视图中显示json格式数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据网格视图中显示数据。我得到的是json格式的响应。如何将数据从json格式转换为数据网格视图数据以显示数据

解决方案

将json数据提取到datatable,然后将datatable分配给datagridview的数据源属性

http://stackoverflow.com/questions/11981282/how-to-convert-json-to-datatable-in-c-sharp [< a href =http://stackoverflow.com/questions/11981282/how-to-convert-json-to-datatable-in-c-sharptarget =_ blanktitle =New Window> ^ ]

http://james.newtonking.com/pages/json-net。 aspx [ ^ ]

快乐编码!

:)


这可以帮到你:



<一个href =http://www.codeproject.com/Articles/609027/Displaying-JSON-from-PHP-into-a havenGridView-using>使用Json.NET将PHP从JSON中显示为DataGridView ^ ]


试试这个:)



 {
HttpWebRequest request =(HttpWebRequest)WebRequest.Create( https:// your json URL);

// & tracking_number =+ txtttnumber.Text +& courier = + ddlcourier.SelectedValue

HttpWebResponse response =(HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null ;

if (response.CharacterSet == null
readStream = new StreamReader(receiveStream);
else
readStream = new StreamReader(receiveStream,Encoding .GetEncoding(response.CharacterSet));
// List< string> list = new List< string>();
// 将JSON对象转换为String
string data = readStream.ReadToEnd();
// 将JSON对象转换为字典
字典<字符串,对象> dict = new JavaScriptSerializer()。Deserialize< Dictionary< string,object>>(data);


// 转换为变量
< span class =code-keyword> var GridData = dict [ checkpoints] ;

GridView1.DataSource = GridData;
GridView1.DataBind();

//
//


}
}


i want to display the data in the data grid view.the response i am getting in the json format .how to convert the data from json format to data grid view data to display the data

解决方案

extract json data to datatable then assign datatable to datagridview's datasource property
http://stackoverflow.com/questions/11981282/how-to-convert-json-to-datatable-in-c-sharp[^]
http://james.newtonking.com/pages/json-net.aspx[^]
Happy Coding!
:)


This can help you:

Displaying JSON from PHP into a DataGridView using Json.NET[^]


Try This one :)

{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://your json URL");

                //&tracking_number=" + txtttnumber.Text + "&courier=" + ddlcourier.SelectedValue

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream receiveStream = response.GetResponseStream();
                    StreamReader readStream = null;

                    if (response.CharacterSet == null)
                        readStream = new StreamReader(receiveStream);
                    else
                        readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                    //  List<string> list = new List<string>();
//Convert JSON object into String
                    string data = readStream.ReadToEnd();
//Convert JSON object into Dictionary
 Dictionary<string, object> dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(data);

                  
//Convert into variable
                    var GridData= dict["checkpoints"];

GridView1.DataSource=GridData;
GridView1.DataBind();

//
//


                         }
 }


这篇关于需要帮助在数据网格视图中显示json格式数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆