Answer the question
In order to leave comments, you need to log in
How to refer to an array element?
I'm trying to write a simple program for my needs.
I get the required data in JSON. Then they need to be brought to the form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using Newtonsoft.Json;
namespace salatTime
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var json = new WebClient().DownloadString("http://muslimsalat.com/daily.json?key=319b6e0c9e5d35b7d5dd8455ddbcf90e");
VremaNamaza json_deserealize = JsonConvert.DeserializeObject<VremaNamaza>(json);
//MessageBox.Show(json_deserealize.link);
label7.Text = json_deserealize.Items[0].asr;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
public class TodayWeather
{
public object pressure { get; set; }
public string temperature { get; set; }
}
public class Item
{
public string date_for { get; set; }
public string fajr { get; set; }
public string shurooq { get; set; }
public string dhuhr { get; set; }
public string asr { get; set; }
public string maghrib { get; set; }
public string isha { get; set; }
}
public class VremaNamaza
{
public string title { get; set; }
public object query { get; set; }
public string @for { get; set; }
public int method { get; set; }
public string prayer_method_name { get; set; }
public string daylight { get; set; }
public string timezone { get; set; }
public string map_image { get; set; }
public string sealevel { get; set; }
public TodayWeather today_weather { get; set; }
public string link { get; set; }
public string qibla_direction { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string address { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
public string country_code { get; set; }
public List<Item> items { get; set; }
public int status_valid { get; set; }
public int status_code { get; set; }
public string status_description { get; set; }
}
}
Answer the question
In order to leave comments, you need to log in
Your Items is a List. This collection allows you to access elements by index, that is, Items[0].asr. What is the problem?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question