Solution:
Download Package Json.NET , will be great utility for problem solving
Struct:
Createastructlikethis:
publicstructLayoutJson{publicLayoutJson(StringIndex,StringValue){_index=Index;_value=Value;}privatestring_index;publicstringIndex{get{return_index;}set{_index=value;}}privatestring_value;publicstringValue{get{returnthis._value;}set{this._value=value;}}}
ReadingroutineandstandardizationofthisJson
//ListadeValoresIList<LayoutJson>ResultJson;//MetodoqueéresponsávelporconectarnaurlebaixaroconteudopublicvoidGetJsonUrl(){WebClientweb=newWebClient();web.DownloadStringCompleted+=web_DownloadStringCompleted;web.DownloadStringAsync(newUri("http://webradioelectro.comxa.com/informacoes.php", UriKind.RelativeOrAbsolute));
}
void web_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string[] results = e.Result.Split(new string[1] { "<!--" }, StringSplitOptions.RemoveEmptyEntries);
if (results.Count() > 0)
{
IEnumerable objetoJson = (IEnumerable)JsonConvert.DeserializeObject(results[0]);
ResultJson = new List<LayoutJson>();
foreach (var item in objetoJson)
{
string[] values = null;
if (DescribeKeyValue(item, ref values))
{
ResultJson.Add(new LayoutJson(values[0], values[1]));
}
}
}
}
}
//Descobre o Valor de cada item
bool DescribeKeyValue(object item, ref string[] values)
{
try
{
if (item != null)
{
values = item.ToString().Replace("{", "").Replace("}", "").Split(':');
return true;
}
return false;
}
catch
{
return false;
}
}
Notes:
Notice that in the routine a Split
was used in the return of the site content, because it came like this:
Thatis,thestring
wassplittoonlygetJson
.
AnotherimportantfactoristhatthisJsondoesnotfollowastandard,soitcreatesastruct
tostoreeachpositionofthesame,ifithadadefaultitwouldmakeaJsonConvert.DeserializeObject<T>
,whereT
wouldbeclass
orstruct
Result
10 items were obtained with Index and Value, now just work on programming like this:
foreach (LayoutJson item in ResultJson)
{
//item.Index
//item.Value
}
or, as you prefer