D
D
Dmitry Filandor2016-12-19 12:59:09
.NET
Dmitry Filandor, 2016-12-19 12:59:09

How to translate php code to c# + arrays?

Hello!
I have this code:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$url = 'http://api.sypexgeo.net/xml/'. $ip .'';
$xml = simplexml_load_string(file_get_contents($url));
$loc_array = array($xml->ip->city->lat,$xml->ip->city->lon);
$loc_safe = array();
foreach($loc_array as $loc){
    $loc_safe[] = urlencode($loc);
}
$loc_string=implode(',', $loc_safe);
$json = file_get_contents('http://api.wunderground.com/api/ывывывыв/satellite/webcams/forecast/q/' . $loc_string . '.json');
$json = str_replace('Monday', 'Понедельник', $json); 
$json = str_replace('Tuesday', 'Вторник', $json); 
$json = str_replace('Wednesday', 'Среда', $json); 
$json = str_replace('Thursday', 'Четверг', $json); 
$json = str_replace('Friday', 'Пятница', $json); 
$json = str_replace('Saturday', 'Суббота', $json); 
$json = str_replace('Sunday', 'Воскресенье', $json);

$obj = json_decode($json, true);

?>

 
 
<?

$html .= "</h2><table cellpadding=4 cellspacing=3><tr>";
 
  foreach ($obj['forecast']['simpleforecast']['forecastday'] as $arr) {
 
    $html .= "<td align='center'>" . $arr['date']['weekday'] . "<br />";
    $html .= "<img src='http://icons-pe.wxug.com/i/c/k/" . $arr['icon'] . ".gif' border=0 /><br />";
    $html .= "<font color='red'>" . $arr['high']['celsius'] . '&deg;C' . " </font>";
    $html .= "<font color='blue'>" . $arr['low']['celsius'] . '&deg;C' . "</font>";
    $html .= "</td>";
 
 
  }
  $html .= "</tr></table>";

echo $html;
?>

pulls the weather service, I'm trying to transfer it to sharp (asp mvc):
that's where I stopped
public ActionResult pogoda()
        {

            var json = "http://api.wunderground.com/api/ывывывыв/satellite/webcams/forecast/q/16.96591,21.9974.json";

  System.Web.Script.Serialization.JavaScriptSerializer ser = new System.Web.Script.Serialization.JavaScriptSerializer();
            var JSONString = ser.Serialize(json); //JSON encoded

immediately substituted my longitude / latitude, but something is wrong Serialize
and how now

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Zolotov, 2016-12-19
@SZolotov

wrong. pull url with httpclient and get json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question