Answer the question
In order to leave comments, you need to log in
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'] . '°C' . " </font>";
$html .= "<font color='blue'>" . $arr['low']['celsius'] . '°C' . "</font>";
$html .= "</td>";
}
$html .= "</tr></table>";
echo $html;
?>
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question