2016-02-13 37 views
0

我已經創建了簡單的shopify應用程序來檢索產品詳細信息。從服務器使用.net顯示json數據網格視圖

當我從gihub訪問代碼時。

它成功運行並在文本框中顯示產品詳細信息。

我需要進行簡單的更改以在網格視圖中顯示產品詳細信息。

這裏是dafault.aspx:

現有的代碼;

的Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" codefile="Default.aspx.cs" Inherits="SampleWebApplication._Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <asp:TextBox ID="APIOutput" TextMode="MultiLine" runat="server"></asp:TextBox> 

    </div> 

    </form> 
</body> 
</html> 

這裏是我的輸出截圖http://s22.postimg.org/xj9zacxa9/untitled.jpg

我需要顯示在GridView的產品細節,

default.cs:

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using ShopifyAPIAdapterLibrary; 
using System.Configuration; 
using System.Web.Services; 

namespace SampleWebApplication 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      ShopifyAuthorizationState state = HttpContext.Current.Session["Shopify.AuthState"] as ShopifyAuthorizationState; 
      ShopifyAPIClient client 
       = new ShopifyAPIClient(state); 
      APIOutput.Text = (string)client.Get("/admin/products.json"); 
     } 
    } 
} 

但我只是與代碼文件混淆,任何人都可以幫助我獲得產品gridview中的細節?

任何幫助將不勝感激。

在此先感謝。

+0

添加一個gridview控件,將JSON反序列化爲一個對象列表,將列表綁定到gridview。 – Tim

+0

其實我是新來的.net ..你能指導我嗎?謝謝 – pcs

回答

0
<%@ Page Language="C#" AutoEventWireup="true" codefile="Default.aspx.cs" Inherits="SampleWebApplication._Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <asp:GridView ID="GridView1" runat="server"> 
    </asp:GridView> 

    </div> 

    </form> 
</body> 
</html> 

和default.cs代碼如下:

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using ShopifyAPIAdapterLibrary; 
using System.Configuration; 
using System.Web.Services; 

namespace SampleWebApplication 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      ShopifyAuthorizationState state = HttpContext.Current.Session["Shopify.AuthState"] as ShopifyAuthorizationState; 
      ShopifyAPIClient client 
       = new ShopifyAPIClient(state); 
      string shopData = (string)client.Get("/admin/products.json"); 
      JavascriptSerializer serializer = new JavascriptSerializer(); 
      // Here Product is a object class which contains all of the attribute that JSON has. 
      List<Product> lstProduct = serializer.Deserialize<Product>(shopData); 
      GridView1.DataSource = lstProduct; 
      GridView1.DataBind(); 
     } 
    } 
} 

和產品類是這樣的:

public Class Product 
{ 
    // Here is all the properties you want to discribed. 
    // This property is same as the property available in your JSON file. 
} 

希望這將有助於。

+0

對我來說,在這個JavascriptSerializer和產品顯示錯誤.. – pcs

+0

您需要添加參考爲JavascriptSerializer,爲此添加System.Web.Extensions.dll在您的參考和解決參考錯誤。對於產品,產品是您需要創建的類,在此類中,屬性是JSON中可用的屬性。 –

+0

嗨..如果我添加System.Web.Extensions.dll ..它顯示這個網站已經引用程序集.. – pcs

相關問題