Skip to content Skip to sidebar Skip to footer

Display Image Using Json

There is a gridview in which I want to display a image. I want to use this json below to diplay image in my gridview. I have an ImageAdapter class in ImageAdapter class I have Asyn

Solution 1:

This example may help you It is one of the sample example

voidMainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("(link for fetching json data)");
        myReq.Method = WebRequestMethods.Http.Get;
        myReq.Accept = "apllication/json";
        var response = (HttpWebResponse)myReq.GetResponse();
        string myString= response.GetResponseHeader("Registration_Status");
        using (var sr = new StreamReader(response.GetResponseStream()))
        {
            json = sr.ReadToEnd();

            StreamWriter sw = new StreamWriter(@"D:\others\DemoCreatingCustomEvents\TextFile1.txt");
            sw.Write(label1.Content.ToString());
            sw.Close();
        }
    }

    string json="";

    privatevoidbutton1_Click(object sender, RoutedEventArgs e)
    {

        ProductCategory deserializedProdCategory = new ProductCategory();
        MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedProdCategory.GetType());

        deserializedProdCategory = ser.ReadObject(ms) as ProductCategory;
        ms.Close();
//you can fetch the data here and it is shown in label
            label1.Content = deserializedProdCategory.ProdCategory[1].Product_ID + "//" + deserializedProdCategory.ProdCategory[1].Product_Name;
        }
        publicclassProductCategory
        {
            public List<Product> ProdCategory = new List<Product>();
            publicProductCategory()
            {
                ProdCategory = new List<Product>();
            }
        }


        publicclassProduct
        {
            publicint Product_ID { get; set; }
            publicstring Product_Code { get; set; }
            publicstring Product_Name { get; set; }
            public Uri Image_Small { get; set; }
        }

Solution 2:

Entity layer for your code

publicclassCountry
{
    publicstring id { get; set; }
    publicstring first_name { get; set; }
    publicstring last_name { get; set; }
    publicstring username { get; set; }
    publicstring password { get; set; }
    publicstring email { get; set; }
    publicstring photo { get; set; }
    publicstring frame { get; set; }
}

publicclassMyData
{
    public List<Country> countries { get; set; }
}

By using this you can modify it by seeing the above example

Post a Comment for "Display Image Using Json"