Asp.net C# ile Json verisi okuma
SanalData’yı Google’da tercih edilen kaynak olarak ekleyinMerhabalar,
Öncelikle buradan ” Newtonsoft.Json.dll (4.5)” ( Json netframework 3.5 için olanı ise buradan indirebilirsiniz ) dosyamızı indirelim. Daha sonra kütüphanelerimizi yüklüyoruz.
|
1 2 3 4 5 6 7 8 9 10 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Newtonsoft.Json; using System.IO; using System.Net; using System.Text.RegularExpressions; |
Class’ımızı oluşturuyoruz. Burdaki objeleri jsondaki verilere göre kendinizi oluşturucaksınız
Örnek class
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class RootObject { public int SEMBOLID { get; set; } public string SEMBOL { get; set; } public string ACIKLAMA { get; set; } public double YUZDEDEGISIM { get; set; } public double NET { get; set; } public DateTime TARIH { get; set; } public double YUKSEK { get; set; } public double DUSUK { get; set; } public double DUNKUKAPANIS { get; set; } public double ACILIS { get; set; } public double KAPANIS { get; set; } public double ALIS { get; set; } public double SATIS { get; set; } public double HACIMTL { get; set; } public int OrderId { get; set; } } |
Daha sonra page load kısmına aşağıdaki kodları yapıştırın gitsin 🙂
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
HttpWebRequest request = WebRequest.Create("json urlsi") as HttpWebRequest; string jsonVerisi = ""; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); jsonVerisi = reader.ReadToEnd(); } IEnumerable<RootObject> result = JsonConvert.DeserializeObject<IEnumerable<RootObject>>(jsonVerisi ); foreach (RootObject r in result) { Response.Write(r.SEMBOL + " : " + r.SATIS + " Değişim "+r.YUZDEDEGISIM+"<br>"); } |
Bir başka örnek kod
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
class Program { static void Main(string[] args) { string data = "{\"id\": \"100\", \"ad\": \"Sanal\", \"soyad\": \"Data\"}"; Kisi k = JsonConvert.DeserializeObject<Kisi>(data); Console.Write(k.ad); Console.ReadLine(); } } public class Kisi { public int id { get; set; } public string ad { get; set; } public string soyad { get; set; } } |
Eğerki json yapınızda alt bir json varsa yani aşağıdak gibiyse
Aşağıdaki gibi json okuma işlemlerini yapabilirsiniz.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
protected void Page_Load(object sender, EventArgs e) { try { string kelime = Request.QueryString["kelime"]; ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; HttpWebRequest request = WebRequest.Create("json linki") as HttpWebRequest; string data = ""; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); data = reader.ReadToEnd(); } icerikler k = JsonConvert.DeserializeObject<icerikler>(data); for (Int32 i = 0; i <= 199; i++) { Response.Write(k.hits[i].id + " = " + k.hits[i].tags + " = " + k.hits[i].largeImageURL+"<br>"); } } catch(Exception exp) { Response.Write(exp.Message); } } public class icerikler { public int total { get; set; } public List<resimler> hits { get; set; } } public class resimler { public string largeImageURL { get; set; } public string tags { get; set; } public int id { get; set; } } |
Günün zaman çizelgesi
Haber eklenme saatine göre sıralanır.
- Bugün
- HarmonyOS kurulumları 100 milyonu aştı, Huawei doğrulamadı
- OSD: 2026’nın ilk 10 ayında otomobil üretimi yüzde 17 düştü
- Galaxy S27 Pro ve Ultra’nın Kamera Tasarımı Sızdı
- Alfa Romeo Kasım 2026 Fiyatları ve Kampanyaları
- Galaxy Claw, Galaxy AI’ı uygulamalarda görev yapan ajana dönüştürebilir
- HLTH USA 2026, sağlık teknolojilerini Las Vegas’ta buluşturuyor
- God of War Ascension’ın PC uyarlaması yayımlandı
- Gemini, ChatGPT ve Claude Amazon dolandırıcılığını test etti
- Apple’ın iPhone Duo için dört geliştirme hedefi
- Telefon Çekmiyorsa Deneyebileceğiniz Çözümler
- IPTV Nedir? Yasal Yayınlarla Kaçak Servis Arasındaki Fark
- Windows 11 Çalıştır penceresi yenileniyor: Gözat yok
- Apple TV 4K’da 8 GB RAM var, uygulama sınırı 2 GB
- Gemini Docs ve Sheets dosyalarını sohbet içinde düzenliyor
