将 Smartsheet 数据导入 Gridview

Smartsheet data into Gridview

我对 Smartsheet 和使用 c# 编程还很陌生。主要是初学者并尝试使用 visual studio 2013 将我的 Web 应用程序与 Smartsheet 集成。我目前正在努力让 gridview 控件填充从 Smartsheet 返回的数据(json 格式)。到目前为止,我已经能够得到 json 字符串,其中包含:

{  
   "id":4705121406871428,
   "name":"Distributors",
   "version":3,
   "totalRowCount":2,
   "accessLevel":"OWNER",
   "effectiveAttachmentOptions":[  
      "DROPBOX",
      "GOOGLE_DRIVE",
      "BOX_COM",
      "FILE"
   ],
   "ganttEnabled":false,
   "dependenciesEnabled":false,
   "permalink":"https://app.smartsheet.com/b/home?lx=xlJ7OtqknyOndgOnClj4qg",
   "createdAt":"2015-06-22T16:55:02+10:00",
   "modifiedAt":"2015-06-23T14:17:47+10:00",
   "columns":[  
      {  
         "id":3238895438587780,
         "index":0,
         "title":"id",
         "type":"TEXT_NUMBER",
         "primary":true,
         "width":150
      },
      {  
         "id":7742495065958276,
         "index":1,
         "title":"distName",
         "type":"TEXT_NUMBER",
         "width":150
      },
      {  
         "id":2112995531745156,
         "index":2,
         "title":"agency",
         "type":"TEXT_NUMBER",
         "width":150
      },
      {  
         "id":6616595159115652,
         "index":3,
         "title":"profile",
         "type":"TEXT_NUMBER",
         "width":150
      }
   ],
   "rows":[  
      {  
         "id":3999757174630276,
         "rowNumber":1,
         "expanded":true,
         "createdAt":"2015-06-23T11:05:26+10:00",
         "modifiedAt":"2015-06-23T14:17:47+10:00",
         "cells":[  
            {  
               "columnId":3238895438587780,
               "type":"TEXT_NUMBER",
               "value":1.0,
               "displayValue":"1"
            },
            {  
               "columnId":7742495065958276,
               "type":"TEXT_NUMBER",
               "value":"ABS",
               "displayValue":"ABS"
            },
            {  
               "columnId":2112995531745156,
               "type":"TEXT_NUMBER",
               "value":"ShedsRus",
               "displayValue":"ShedsRus"
            },
            {  
               "columnId":6616595159115652,
               "type":"TEXT_NUMBER",
               "value":"OK",
               "displayValue":"OK"
            }
         ]
      },
      {  
         "id":8503356802000772,
         "rowNumber":2,
         "siblingId":3999757174630276,
         "expanded":true,
         "createdAt":"2015-06-23T11:05:26+10:00",
         "modifiedAt":"2015-06-23T14:17:47+10:00",
         "cells":[  
            {  
               "columnId":3238895438587780,
               "type":"TEXT_NUMBER",
               "value":2.0,
               "displayValue":"2"
            },
            {  
               "columnId":7742495065958276,
               "type":"TEXT_NUMBER",
               "value":"Barns",
               "displayValue":"Barns"
            },
            {  
               "columnId":2112995531745156,
               "type":"TEXT_NUMBER",
               "value":"BarnsRus",
               "displayValue":"BarnsRus"
            },
            {  
               "columnId":6616595159115652,
               "type":"TEXT_NUMBER",
               "value":"OK",
               "displayValue":"OK"
            }
         ]
      }
   ]
}

此字符串似乎包含太多信息,例如 ID 和类型等... 我想要的只是我的列名及其相关数据。 然后,将此信息显示为 gridview 控件。

这是我的json请求:

        string sURL;
        sURL = "https://api.smartsheet.com/1.1/sheet/4705121406871428";

        WebRequest wrGETURL;
        wrGETURL = WebRequest.Create(sURL);
        wrGETURL.ContentType = "application/json";
        wrGETURL.Method = "GET";
        wrGETURL.Headers["Authorization"] = "Bearer ******************";

        Stream objStream;
        objStream = wrGETURL.GetResponse().GetResponseStream();

        StreamReader objReader = new StreamReader(objStream);

        string jsonResult = objReader.ReadToEnd();

如果有人能提供一些指导来让我工作,我将不胜感激……请原谅我对这个话题的完全无知……这里是新手!谢谢

在 Smartsheet API 的响应中有一个 columns object,它由 [=30] 中的列数组组成=].遍历此数组以获取列标题和列 ID。

然后,遍历 rows object 并遍历每一行。对于每一行,您需要循环遍历该行的 cells 数组并输出 displayValue。确保单元格的每个 columnId 与您正在打印的列的 id 匹配,因为如果您在 Smartsheet 中有一个空白单元格,则不会有单元格 object由 Smartsheet API.

返回

您可以在 Smartsheet API 中找到有关 Smartsheet API here. And, If you haven't already done so, I would also recommend checking out the C# SDK 的更多信息。