2013-01-17 4 views
-3

누구나 ASP.Net에서 JSON을 사용하는 방법을 도와 줄 수 있습니까? 나는 AJAX와 JQuery를 알지 못한다. 나는 초보자이다. (ASP.Net 및 콘솔 응용 프로그램에서 모두 구현할 수 있는지 여부)JSON을 .net으로 어떻게 사용하고 구현할 수 있습니까?

+1

먼저 자습서를 시도하고 google에서 검색하십시오. –

+0

참조이 [닷넷에서 JSON을 사용하는 방법] [1] [1] : http://stackoverflow.com/questions/13447608/display-image-using-json/13447855#13447855 – ravithejag

답변

0
void MainWindow_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=""; 

private void button1_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; 
    } 
    public class ProductCategory 
    { 
     public List<Product> ProdCategory = new List<Product>(); 
     public ProductCategory() 
     { 
      ProdCategory = new List<Product>(); 
     } 
    } 


    public class Product 
    { 
     public int Product_ID { get; set; } 
     public string Product_Code { get; set; } 
     public string Product_Name { get; set; } 
     public Uri Image_Small { get; set; } 
    } 
관련 문제