-
Üyelik
15.11.2013
-
Yaş/Cinsiyet
28 / E
-
Meslek
Öğrenci
-
Konum
İstanbul Anadolu
-
Ad Soyad
Y** S**
-
Mesajlar
47
-
Beğeniler
5 / 0
-
Ticaret
0, (%0)
Arkadaşlar elimde bi php kodu var bunu c# cevirmem lazım php bilmedigim için mantıgını anlamıyorum lütfen yardım edin
function piyasa() {
$json = file_get_contents("http://api.piyasa.com/json/?kaynak=doviz_guncel_serb");
$array = json_decode($json, TRUE);
for($i=0;$i $foex = $array[$i]["foex"];
$piyasa[$foex]["buy"] = $array[$i]["buy"];
$piyasa[$foex]["sell"] = $array[$i]["sell"];
if($array[$i]["change"]==0) $piyasa[$foex]["change"] = "pause";
else if($array[$i]["change"]>0) $piyasa[$foex]["change"] = "up";
else $piyasa[$foex]["change"] = "down";
$piyasa[$foex]["time"] = $array[$i]["time"];
}
return $piyasa;
}
$array = piyasa();
?>
yasinsarica.com
-
Üyelik
25.01.2014
-
Yaş/Cinsiyet
26 / E
-
Meslek
Girişimci
-
Konum
Ankara
-
Ad Soyad
E** C**
-
Mesajlar
34
-
Beğeniler
15 / 6
-
Ticaret
0, (%0)
c# json okuma diye aratın.
-
Üyelik
25.06.2012
-
Yaş/Cinsiyet
38 / E
-
Meslek
Engineering Director
-
Konum
İstanbul Avrupa
-
Ad Soyad
T** C**
-
Mesajlar
771
-
Beğeniler
2 / 260
-
Ticaret
0, (%0)
[{"foex":"USD","buy":"2.1360","sell":"2.1370","change":"-0.790","time":"14:20"},{"foex":"EUR","buy":"2.8640","sell":"2.8650","change":"-0.865","time":"14:20"},{"foex":"GBP","buy":"3.5740","sell":"3.5920","change":"-0.832","time":"14:20"},{"foex":"CHF","buy":"2.3500","sell":"2.3640","change":"-0.802","time":"14:20"},{"foex":"JPY","buy":"0.0208","sell":"0.0210","change":"-0.952","time":"14:20"},{"foex":"CAD","buy":"1.9400","sell":"1.9500","change":"-0.818","time":"14:20"},{"foex":"DKK","buy":"0.3826","sell":"0.3841","change":"-0.804","time":"14:20"},{"foex":"SEK","buy":"0.3084","sell":"0.3096","change":"-0.963","time":"14:20"},{"foex":"NOK","buy":"0.3410","sell":"0.3426","change":"-0.814","time":"14:20"},{"foex":"AUD","buy":"1.9730","sell":"1.9890","change":"-0.854","time":"14:20"},{"foex":"RUB","buy":"0.0598","sell":"0.0598","change":"0.000","time":"14:20"},{"foex":"SAR","buy":"0.5677","sell":"0.5708","change":"-0.804","time":"14:20"},{"foex":"KWD","buy":"7.4550","sell":"7.5920","change":"-0.785","time":"14:20"},{"foex":"BHD","buy":"5.6600","sell":"5.7390","change":"-1.394","time":"11:00"},{"foex":"BGN","buy":"1.4690","sell":"1.4750","change":"-1.343","time":"11:00"},{"foex":"IRR","buy":"0.0081","sell":"0.0081","change":"-1.220","time":"14:20"},{"foex":"CNY","buy":"0.3490","sell":"0.3502","change":"-1.329","time":"11:00"},{"foex":"AED","buy":"0.5842","sell":"0.5875","change":"-1.384","time":"11:00"},{"foex":"BRL","buy":"0.9376","sell":"0.9465","change":"-0.836","time":"11:00"},{"foex":"CZK","buy":"0.1034","sell":"0.1037","change":"-1.430","time":"11:00"},{"foex":"EGP","buy":"0.2904","sell":"0.2905","change":"0.103","time":"11:16"},{"foex":"HKD","buy":"0.2582","sell":"0.2583","change":"0.116","time":"11:16"},{"foex":"HUF","buy":"0.0092","sell":"0.0092","change":"0.000","time":"11:00"},{"foex":"IDR","buy":"0.0002","sell":"0.0002","change":"0.000","time":"11:16"},{"foex":"INR","buy":"0.0351","sell":"0.0352","change":"-1.127","time":"11:00"},{"foex":"KRW","buy":"0.0019","sell":"0.0019","change":"0.000","time":"11:16"},{"foex":"LVL","buy":"3.8442","sell":"3.8426","change":"0.185","time":"11:16"},{"foex":"MXN","buy":"0.1622","sell":"0.1627","change":"-0.977","time":"11:00"},{"foex":"MYR","buy":"0.6192","sell":"0.6189","change":"-0.434","time":"11:16"},{"foex":"NZD","buy":"1.8050","sell":"1.8370","change":"-1.312","time":"11:00"},{"foex":"PHP","buy":"0.0461","sell":"0.0461","change":"0.000","time":"11:16"},{"foex":"PLN","buy":"0.6844","sell":"0.6899","change":"-0.711","time":"11:00"},{"foex":"RON","buy":"0.6464","sell":"0.6523","change":"-1.238","time":"11:00"},{"foex":"SGD","buy":"1.5950","sell":"1.5950","change":"0.038","time":"11:16"},{"foex":"THB","buy":"0.0639","sell":"0.0638","change":"0.000","time":"11:16"},{"foex":"ZAR","buy":"0.2014","sell":"0.2024","change":"-0.346","time":"11:00"}]
Url'den gelen data json formatında, yukarıdaki gibi.
Sizin yukarıdaki data daki gibi bir model sınıfı oluşturmanız gerekir.
public class JSonModelData {
private string foex;
private string buy;
private string sell;
private string change;
private string time;
//get,set
}
http://james.newtonking.com/json linkteki api ile gelen json verisini deserilize etmeniz gerekmektedir.
yukarıdaki datayı ;
URL'den datayı çekmek için;
string json = var json = new WebClient().DownloadString("url");
Kaynak
Gelen veriyi JSON API 'si ile modelimize çevirmek için desirilize ediyoruz. List Model'imize dolduruyoruz.
List modelList = JsonConvert.DeserializeObject(json );
Sonrasında foreach ile loop içinde dönüp,
foreach (string model in modelList )
{
//modeli yazdırabilirsiniz.
Console.WriteLine(model.foex + " " + model.buy);
}
https://www.linkedin.com/in/turgaycan/
Kaliteli kod yazılır.. (Günlük/Saatlik ücreti ile)