I am trying to read JSON data from web, and i am using Json.net library for this task, the problem is if there is only one json object
{"id":"2340","time":"2014-10-29 16:26:49"}
everything works fine, but if there is an array of them
[{"id":"2340","time":"2014-10-29 16:26:49"}, {"id":"2341","time":"2014-10-29 16:27:21"}]
Program isn't working.
using System;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Collections.Specialized;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace Localhostnet
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (WebClient client = new WebClient())
{
string htmlCode = client.DownloadString('http://localhost/json.php');
LocalhostTiming jsonResponse = JsonConvert.DeserializeObject<LocalhostTiming>(htmlCode);
string timeId = jsonResponse.id;
MessageBox.Show(timeId);
}
}
}
public class LocalhostTiming
{
public string id { get; set; }
public string time { get; set; }
}
}
I've tried to add
public class DataContainer
{
public List<LocalhostTiming> LocalhostTiming{ get; set; }
}
But i dont know how to work with this code.